oltu-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Prateek (JIRA)" <j...@apache.org>
Subject [jira] [Reopened] (OLTU-210) OAUTH_APPROVAL_ERROR_GENERIC : An unexpected error has occured during authentication. Please try again in salesforce integration ?
Date Wed, 25 Oct 2017 16:42:00 GMT

     [ https://issues.apache.org/jira/browse/OLTU-210?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Prateek reopened OLTU-210:
--------------------------

There is no issue with the salesforce as I said. The code is working with RestTemplate and
HttpClient. The issue is in the code API OAuthResourceResponse.

> 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)

Mime
View raw message