I am trying to get the code from json using below url using postman.but could able to get the code in json.
Moreover when i hit this url in browser i am redirecting to my localhost url with query parameter where i can get the code.
Step 1. Create an OAuth2Credentials object with your client ID, client secret, scopes, and a redirect callback URI to capture the user’s authorization code.
SessionConfiguration config = new SessionConfiguration.Builder()
.setClientId("YOUR_CLIENT_ID")
.setClientSecret("YOUR_CLIENT_SECRET")
.setScopes(yourScopes)
.setRedirectUri(redirectUri)
.build();
OAuth2Credentials credentials = new OAuth2Credentials.Builder()
.setSessionConfiguration(config)
.build()
Step 2. Navigate the user to the authorization URL from the OAuth2Credentials object.
String authorizationUrl = credentials.getAuthorizationUrl();
Step 3. Once the user approves the request, you get an authorization code. Create a credential object to store the authorization code and the user ID.
Credential credential = credentials.authenticate(authorizationCode, userId);
I am confused with step 2 and step 3.
- what should i have to do with authorizationUrl in step 2 ?. - How can i get authorizationCode in step 3 using authorizationUrl?.
You should follow the OAuth2.0 process, documented in the developer docs. Basically, you configure your OAuth2.0 settings. Your settings will generate a specific authentication URL (including client_id and scopes requested). This URL needs to be opened in a webview. Your users have to login with their Uber account and either approve or deny access to the scopes. This is the URL you get in step 2.
If the users click on approve in the auth webview, the configured redirect URI will be called through the Uber server. This callback will have a URL parameter for the authorizationCode.