Last active
August 12, 2016 08:59
-
-
Save xcommerce-gists/4519761 to your computer and use it in GitHub Desktop.
PayPalAccessOpenIDConnectOAuth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//download the complete java code sample from https://github.com/paypal/paypal-access | |
/** | |
* Gets Access token by going to token service. Code is left blank so that user can fill it up manually. | |
* | |
* @return - Access token | |
*/ | |
private static String getAccessToken(String authorizationCode) { | |
StringBuilder tokenUrl = new StringBuilder( | |
"https://api.paypal.com/v1/identity/openidconnect/tokenservice"); | |
tokenUrl.append("?grant_type=authorization_code"); | |
// code should be obtained manually and pasted here. | |
tokenUrl.append("&code=" + authorizationCode); | |
Map<String, Object> responseMap = getResponse(tokenUrl.toString(), "POST", "Basic " + getAuthorizationHeader()); | |
return (String) responseMap.get("access_token"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//download the complete java code sample from https://github.com/paypal/paypal-access | |
/** | |
* Creates an authorization URL so that user can paste this in browser to get authorization code. | |
* | |
* @return - Authorization URL | |
*/ | |
private static String getAuthorizationUrl() { | |
StringBuilder authUrl = new StringBuilder( | |
"https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize"); | |
// all the below params should be changed according to your needs. Below values are just an example. | |
authUrl.append("?client_id=<REPLACE ME>"); | |
authUrl.append("&response_type=code"); | |
authUrl.append("&scope=openid profile email address"); | |
authUrl.append("&nonce=" + createNonce()); | |
authUrl.append("&redirect_uri=<URL GIVEN WHILE REGISTERING THE APP>"); | |
return authUrl.toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//download the complete java code sample from https://github.com/paypal/paypal-access | |
/** | |
* Gets user info based on <code>accesstoken</code> passed. | |
* | |
* @param accessToken - Access token acquired via token service. | |
* @return - User Information map. | |
*/ | |
private static Map<String, Object> getUserInfo(String accessToken) { | |
StringBuilder userInfoUrl = new StringBuilder( | |
"https://api.paypal.com/v1/identity/openidconnect/userinfo"); | |
userInfoUrl.append("?schema=openid"); | |
return getResponse(userInfoUrl.toString(), "GET", ("Bearer " + accessToken)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/38910575/how-to-get-access-token-paypal-in-android i need help here