package io.github.trevornelson;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiMethod.HttpMethod;
import com.google.api.server.spi.response.UnauthorizedException;
import com.google.appengine.api.users.User;
import io.github.trevornelson.Account;

@Api(
    name = "dashboards",
    version = "v1",
    scopes = {Constants.EMAIL_SCOPE},
    clientIds = {Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID, Constants.IOS_CLIENT_ID},
    audiences = {Constants.ANDROID_AUDIENCE}
)
public class Dashboards {

	private String extractUsername(String emailAddress) {
		return emailAddress.split("@")[0];
	}
	
	@ApiMethod(name = "dashboards.createAccount", httpMethod = HttpMethod.POST)
	public Account CreateAccount(final User user, String accountUsername) throws UnauthorizedException {
		
		if (user == null) {
			throw new UnauthorizedException("Authentication is required");
		}
		
		String email = user.getEmail();
		String username = extractUsername(email);
		String userId = user.getUserId();
		
		Account account = new Account(userId, username, email);
		
		return account;
	}
	
	

}

@@ -479,95 +479,30 @@
 ts.A
-NDROID_CLIENT_ID, Constants.IOS_CLIENT_ID%7D,%0A    audiences = %7BConstants.ANDROID_AUDIENCE
+PI_EXPLORER_CLIENT_ID 
 %7D%0A)%0A
@@ -751,32 +751,8 @@
 user
-, String accountUsername
 ) th

Add unauthorized exception to CreateAccount api method