Skip to content

Instantly share code, notes, and snippets.

@balvinder294
Created July 27, 2020 08:21
Show Gist options
  • Save balvinder294/6672de5fa77b83674643733d9f10086f to your computer and use it in GitHub Desktop.
Save balvinder294/6672de5fa77b83674643733d9f10086f to your computer and use it in GitHub Desktop.
Methods to handle social redirect when using popup for authorization with Apple SignIn with response type as form-post for a subdomain
/**
* Redirect User to Social verify to complete social media authorization
*
* @param state the state parameter containing BoxDomain for verification
* @param code the authorization code
* @param httpServletResponse the response with redirection for url
*
* @throws IOException
*/
@GetMapping(value = "/social-login/authorize")
public void forwardSocialAuthorization(@RequestParam String state, @RequestParam Optional<String> code, HttpServletResponse httpServletResponse) throws IOException {
String decodedStateParam = URLDecoder.decode(state, "UTF-8");
JSONObject stateParams = new JSONObject(decodedStateParam);
// your state param here, i added as just state
String subDomain = stateParams.getString("subDomain");
if(code.isPresent()){
httpServletResponse.sendRedirect(redirectSocialVerifyUrl(subDomain, code.get()));
}
}
/**
* Url for redirecting user based on subdomain from where authorization is requested
*
* @param subDomain the domain of the box
* @param code the authorization code
* @return the redirect to verfy social
*/
String redirectSocialVerifyUrlApple(String subDomain, String code, Optional<String> idToken, Optional<String> user) {
String redirectUrl = "https://" + boxDomain + "/verify-social" + "?code=" + code;
if (idToken.isPresent()) {
redirectUrl = redirectUrl + "idToken=" + idToken.get();
}
if (user.isPresent()) {
redirectUrl = redirectUrl + "user=" + user.get();
}
return redirectUrl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment