Skip to content

Instantly share code, notes, and snippets.

@balvinder294
Last active July 27, 2020 08:21
Show Gist options
  • Save balvinder294/abaf08910affb08314f032127d4790b8 to your computer and use it in GitHub Desktop.
Save balvinder294/abaf08910affb08314f032127d4790b8 to your computer and use it in GitHub Desktop.
Method to create Authorization Url for Apple Sign in Auhtorization for a user
import org.json.JSONObject;
/******
*To create authorization url for social sign in
this url will open authentication window for apple sign in
for a subdomain as state param
*****/
public String createAuthorizationUrl(String subDomain) {
// I have added jsob objct for encodin state paramters like for getting the curent domain used as we have multiple subdomains, you can add your state parameters here
JSONObject jsonObject = new JSONObject();
jsonObject.put("subDomain", subDomain);
try {
String url = "https://appleid.apple.com/auth/authorize?client_id=" + appleClientId +
"&redirect_uri=" + redirectUrl +
"&response_type=code%20id_token" + // to request code and id token both
"&scope=" + "name%20email" + // scopes are name email
"&response_mode=" + "form_post" + // when we request id token only form_post will be available
"&state=" + URLEncoder.encode(jsonObject.toString(), "UTF-8");
return url;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment