Skip to content

Commit

Permalink
server flow added
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Nov 2, 2017
1 parent d70adc2 commit db53e32
Showing 1 changed file with 44 additions and 8 deletions.
Expand Up @@ -43,21 +43,57 @@ public View getView(String viewId) throws Exception {

view.setResponse(false); // this resource writes the response itself

String state = getEnvironment().getRequest().getParameter("state");
log.warn("TODO: Check state '" + state + "' ...");

HttpServletResponse response = getEnvironment().getResponse();
if (true) {
log.error("Something went wrong!");
response.setStatus(500);
} else {
response.setHeader("Location", "TODO");

try {
String state = getEnvironment().getRequest().getParameter("state");
log.warn("TODO: Check state '" + state + "' ...");
if (true) {
throw new Exception("Checking 'state' parameter failed!");
}

String token_endpoint = getDiscoveryDocument();
String code = getEnvironment().getRequest().getParameter("code");
String id_token = getAccessAndIdToken(token_endpoint, code);
String uniqueUserId = getPayload(id_token);

// TODO: Check whether user with uniqueUserId exists or otherwise create account for this new user

response.setHeader("Location", "en/projects/index.html"); // TODO: Make configurable
response.setStatus(307);
} catch(Exception e) {
log.error(e.getMessage());
response.setStatus(500);
}

return view;
}

/**
* @return URL of token endpoint
*/
private String getDiscoveryDocument() {
// TODO: Make URL configurable and depending on provider, e.g. Google OpenID is using https://accounts.google.com/.well-known/openid-configuration
return "https://www.googleapis.com/oauth2/v4/token"; // TODO: Get URL from discovery document
}

/**
* @return id_token (JSON Web Token, containing user identity information
*/
private String getAccessAndIdToken(String token_endpoint, String code) {
// TODO: Get access and Id token by sending a POST request to token_endpoint, see https://developers.google.com/identity/protocols/OpenIDConnect#server-flow or https://developers.google.com/identity/protocols/OpenIDConnect#exchangecode
return "TODO";
}

/**
* Get user information
*/
private String getPayload(String id_token) {
// TODO: Analyze JWT, e.g. get unique user Id and user email and ... see https://developers.google.com/identity/protocols/OpenIDConnect#obtainuserinfo
//return "michaelwechner@gmail.com"; // TODO: Return 'email'
return "10769150350006150715113082367"; // TODO: Return 'sub'
}

/**
* @see org.wyona.yanel.core.api.attributes.ViewableV2#getViewDescriptors()
*/
Expand Down

0 comments on commit db53e32

Please sign in to comment.