[ https://issues.apache.org/jira/browse/OLTU-210?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16218539#comment-16218539 ]
Prateek commented on OLTU-210: ------------------------------ The following response I received {code:java} REDIRECT TO: https://login.salesforce.com/services/oauth2/authorize?scope=api+full+refresh_token&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fapache-oltu%2Fsalesforce%2Fredirect&client_id=3MVG9d8..z.hDcPJZPIzGJ5UZDrL7bJthAQ_v0YCxzEeG11HI1YwKNfvaYfDy0msJ6azE3ECMB8EGsF3NRtJ0 Received CODE: aPrxshT49BthlzIhcGw5DiH5uLb10ZaFTJ2oDjP6uQyreKy2ASctQlIUCoF9FwBRiaErVhIgkA== POSTING: null Received ACCESS_TOKEN: [ 00D7F0000001I8v!ARgAQBhSAzlEyvhrxmTYmZgAyjh_z_6_qC8zDbyCrSuLUBwqxa3eKSoDjizgQZ0XJHIdh3Nd1xvFUZEN_JXwcxJKDOUgnJaC] Received EXPIRES_IN: [ null] Refresh Token : [5Aep8613hy0tHCYdhxJMolioLtSyVWkdY.qjUQIKBDHpKUfFk6Jir0yeyrOuoPYiPCBXQgonTk8GsMffbRTwhES] {"access_token":"00D7F0000001I8v!ARgAQBhSAzlEyvhrxmTYmZgAyjh_z_6_qC8zDbyCrSuLUBwqxa3eKSoDjizgQZ0XJHIdh3Nd1xvFUZEN_JXwcxJKDOUgnJaC","refresh_token":"5Aep8613hy0tHCYdhxJMolioLtSyVWkdY.qjUQIKBDHpKUfFk6Jir0yeyrOuoPYiPCBXQgonTk8GsMffbRTwhES","signature":"9dyXNAMnfFykhwLeI5x9AY/8tYiyvAALQFiU9SoE8Zw=","scope":"refresh_token api full","id_token":"eyJraWQiOiIyMTAiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdF9oYXNoIjoiVVZuMnVWMi1YRkMyZDZsU3dxcmZ2USIsInN1YiI6Imh0dHBzOi8vbG9naW4uc2FsZXNmb3JjZS5jb20vaWQvMDBEN0YwMDAwMDAxSTh2VUFFLzAwNTdGMDAwMDAwbDJiZ1FBQSIsImF1ZCI6IjNNVkc5ZDguLnouaERjUEpaUEl6R0o1VVpEckw3Ykp0aEFRX3YwWUN4ekVlRzExSEkxWXdLTmZ2YVlmRHkwbXNKNmF6RTNFQ01COEVHc0YzTlJ0SjAiLCJpc3MiOiJodHRwczovL2xvZ2luLnNhbGVzZm9yY2UuY29tIiwiZXhwIjoxNTA4OTM1NjgwLCJpYXQiOjE1MDg5MzU1NjB9.JcOsILTOs3TF2sBgO4l_x6kN27By9XcFyT2MttiECpwH481jxeIEO4A0gKwO5JWvqkMDulqtRNR91XIAP9cj_sTUt4WAtnMzZ3le8Hy2mHeXhD2NjQqm0w5sVFBReqNW8FVlFgHzCRnJn8bA3Y9w8BQVGy815zXNpwrxrFRden4tXzhj6zzqznzlQjnbzWWd2MWp8AepbQF2Xt-IzCceIxbPK7CuIt3U7HciPfC_XoDQXXu3z7wKoySylZy2iHmmE3pBZvSobfO02bZW5pUcRI_YxOqOuWYZbpZsYumSL9RrU9TZ2W136ES2od-y8w_wyRL30ScHuktheWYplIDs_THosP1lBNISfXReAZiYL8T4SWFt7qORQmT3G9TELCBrPBefNdkDwo0tzRxrvOXYwEuHBVvmuRASh9SZZnVeaSpZDMBoOV_0H7XpbnbR1VolGzEjSgt-G_8oLX0ERc-IBoQDakhcU0aYp6re-ln_omrURbdBXadS4DhMQP-oFTsiYfq_fbPo_tCw_2a_kGpIKQHTTchvUaPcy27ghuDd_axXWw-rLTVgpT0kAAwsU3A7DF608L--KssGKgifcJsSCea3cKSMrL6M-k9yzA5bpCDOiU5mAEjBsd2ASI1UVrxhIMgqgS0ahlHzgHTondE31AAH7xLBO2oxswFzvGOXNKA","instance_url":"https://ap5.salesforce.com","id":"https://login.salesforce.com/id/00D7F0000001I8vUAE/0057F000000l2bgQAA","token_type":"Bearer","issued_at":"1508935560200"} Could not access resource: 401 [{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}] {code} The code which I used {code:java} private String getAccessToken(String authorizationCode) throws OAuthSystemException, OAuthProblemException { OAuthClientRequest request = OAuthClientRequest .tokenLocation(ACCESS_TOKEN_URL) .setGrantType(GrantType.AUTHORIZATION_CODE) .setClientId(CLIENT_ID) .setClientSecret(CLIENT_SECRET) .setRedirectURI(REDIRECT_URL) .setCode(authorizationCode) .buildQueryMessage(); //create OAuth client that uses custom http client under the hood OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); OAuthAccessTokenResponse oAuthResponse = oAuthClient.accessToken(request); System.out.println("POSTING: "+request.getBody()); System.out.println("Received ACCESS_TOKEN: [ "+oAuthResponse.getAccessToken() + "]"); System.out.println("Received EXPIRES_IN: [ "+oAuthResponse.getExpiresIn() + "]"); System.out.println("Refresh Token : [" + oAuthResponse.getRefreshToken() + "]"); System.out.println(oAuthResponse.getBody()); request= new OAuthBearerClientRequest("https://ap5.salesforce.com/services/data/v40.0/"). setAccessToken(oAuthResponse.getAccessToken()). buildBodyMessage(); OAuthClient client = new OAuthClient(new URLConnectionClient()); OAuthResourceResponse resourceResponse= client.resource(request, "GET", OAuthResourceResponse.class); if (resourceResponse.getResponseCode()==200){ logger.debug("HTTP OK"); System.out.println(resourceResponse.getBody()); return resourceResponse.getBody(); } else{ System.out.println("Could not access resource: " + resourceResponse.getResponseCode()+ " " + resourceResponse.getBody()); return null; } } {code} > OAUTH_APPROVAL_ERROR_GENERIC : An unexpected error has occured during > authentication. Please try again in salesforce integration ? > ---------------------------------------------------------------------------------------------------------------------------------- > > Key: OLTU-210 > URL: https://issues.apache.org/jira/browse/OLTU-210 > Project: Apache Oltu > Issue Type: Bug > Reporter: Prateek > > I am working on the Spring MVC + Apache Oltu +Salesforce Integration > Example. I got the ClientId and Client Secrete from the salesforce Connected > App. Now I am not sure on the below error. > IMP: Why "authorizationCode" is comming null from salesforce? What all > scopes can be set like setScope("full,refresh_token")?? > What API do we need to used like here we can used for GITHUB ? > {code:java} > GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(request, > GitHubTokenResponse.class); > {code} > What OAuthBearerClientRequest can be used like below ? > {code:java} > request= new > OAuthBearerClientRequest("https://ap5.salesforce.com/5007F000000nxss"). > setAccessToken(oAuthResponse.getAccessToken()). > buildQueryMessage(); > {code} > [OAUTH_APPROVAL_ERROR_GENERIC : An unexpected error has occured during > authentication. Please try again.] > I am using the below code:- > {code:java} > private static final String AUTHORIZATION_URL = > "https://login.salesforce.com/services/oauth2/authorize"; > private static final String CLIENT_ID = > "3MVG9d8..z.hDcPJZPIzGJ5UZDqJOJY.3R6RBM8sJAF8XXXXXXXXXXXXXXXXXXXXXX"; > private static final String CLIENT_SECRET = "375066XXXXX"; > private static final String REDIRECT_URL = > "http://localhost:8080/apache-oltu/salesforce/redirect"; > //private static final String ACCESS_TOKEN_URL = > "https://login.salesforce.com/services/oauth2/token"; > private static final String ACCESS_TOKEN_URL = > "https://ap5.salesforce.com/services/oauth2/token"; > @RequestMapping(value = "/auth", method = RequestMethod.GET) > public String authenticate() throws OAuthSystemException { > OAuthClientRequest request = OAuthClientRequest > .authorizationLocation(AUTHORIZATION_URL) > .setClientId(CLIENT_ID) > .setRedirectURI(REDIRECT_URL) > .setResponseType("code") > .setScope("full,refresh_token") > .buildQueryMessage(); > return "redirect:" + request.getLocationUri(); > } > @RequestMapping(value = "/redirect", method = RequestMethod.GET) > public HttpEntity<String> redirect( > @RequestParam(value = "token", required = false) String > code) throws OAuthSystemException, OAuthProblemException { > String value = "UNKNOWN"; > if (code != null && code.length() > 0) { > String details = getAccessToken(code); > value = details; > } > return new ResponseEntity<String>(value,HttpStatus.OK); > } > private String getAccessToken(String authorizationCode) throws > OAuthSystemException, OAuthProblemException { > OAuthClientRequest request = OAuthClientRequest > .tokenLocation(ACCESS_TOKEN_URL) > .setGrantType(GrantType.AUTHORIZATION_CODE) > .setClientId(CLIENT_ID) > .setClientSecret(CLIENT_SECRET) > .setRedirectURI(REDIRECT_URL) > .setCode(authorizationCode) > .buildBodyMessage(); > //create OAuth client that uses custom http client under the > hood > OAuthClient oAuthClient = new OAuthClient(new > URLConnectionClient()); > GitHubTokenResponse oAuthResponse = > oAuthClient.accessToken(request, GitHubTokenResponse.class); > System.out.println(oAuthResponse.getBody()); > request= new > OAuthBearerClientRequest("https://ap5.salesforce.com/5007F000000nxss"). > setAccessToken(oAuthResponse.getAccessToken()). > buildQueryMessage(); > OAuthClient client = new OAuthClient(new URLConnectionClient()); > OAuthResourceResponse resourceResponse= > client.resource(request, "GET", OAuthResourceResponse.class); > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)