com.google.api.client.auth.oauth.OAuthGetAccessToken Java Examples
The following examples show how to use
com.google.api.client.auth.oauth.OAuthGetAccessToken.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OAuthHmacThreeLeggedFlow.java From google-oauth-java-client with Apache License 2.0 | 6 votes |
public Credential complete(String authorizationCode) throws IOException { Preconditions.checkNotNull(transport, "Must call setHttpTransport before calling complete."); OAuthGetAccessToken accessToken = new OAuthGetAccessToken(authorizationServerUrl); accessToken.temporaryToken = tempToken; accessToken.transport = transport; OAuthHmacSigner signer = new OAuthHmacSigner(); signer.clientSharedSecret = consumerSecret; signer.tokenSharedSecret = tempTokenSecret; accessToken.signer = signer; accessToken.consumerKey = consumerKey; accessToken.verifier = authorizationCode; OAuthCredentialsResponse credentials = accessToken.execute(); signer.tokenSharedSecret = credentials.tokenSecret; OAuthHmacCredential accessCredential = new OAuthHmacCredential( userId, consumerKey, consumerSecret, credentials.tokenSecret, credentials.token); return accessCredential; }
Example #2
Source File: GitLabContext.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
@NotNull public static GitLabToken obtainAccessToken(@NotNull String gitlabUrl, @NotNull String username, @NotNull String password, boolean sudoScope) throws IOException { try { final OAuthGetAccessToken tokenServerUrl = new OAuthGetAccessToken(gitlabUrl + "/oauth/token?scope=api" + (sudoScope ? "%20sudo" : "")); final TokenResponse oauthResponse = new PasswordTokenRequest(transport, JacksonFactory.getDefaultInstance(), tokenServerUrl, username, password).execute(); return new GitLabToken(TokenType.ACCESS_TOKEN, oauthResponse.getAccessToken()); } catch (TokenResponseException e) { if (sudoScope && e.getStatusCode() == HttpURLConnection.HTTP_UNAUTHORIZED) { // Fallback for pre-10.2 gitlab versions final GitlabSession session = GitlabAPI.connect(gitlabUrl, username, password); return new GitLabToken(TokenType.PRIVATE_TOKEN, session.getPrivateToken()); } else { throw new GitlabAPIException(e.getMessage(), e.getStatusCode(), e); } } }
Example #3
Source File: AuthorizationFlow.java From android-oauth-client with Apache License 2.0 | 6 votes |
/** * Returns a new instance of a token request based on the given verifier * code. This step is defined in <a * href="http://oauth.net/core/1.0a/#auth_step3">Obtaining an Access * Token</a>. * * @param temporaryCredentials * @param verifierCode * @return */ public OAuthGetAccessToken new10aTokenRequest(OAuthCredentialsResponse temporaryCredentials, String verifierCode) { OAuthGetAccessToken request = new OAuthGetAccessToken(getTokenServerEncodedUrl()); request.temporaryToken = temporaryCredentials.token; request.transport = getTransport(); OAuthHmacSigner signer = new OAuthHmacSigner(); ClientParametersAuthentication clientAuthentication = (ClientParametersAuthentication) getClientAuthentication(); signer.clientSharedSecret = clientAuthentication.getClientSecret(); signer.tokenSharedSecret = temporaryCredentials.tokenSecret; request.signer = signer; request.consumerKey = clientAuthentication.getClientId(); request.verifier = verifierCode; return request; }
Example #4
Source File: OAuth1DataGenerator.java From data-transfer-project with Apache License 2.0 | 5 votes |
@Override public AuthData generateAuthData( String callbackBaseUrl, String authCode, String id, AuthData initialAuthData, String extra) { Preconditions.checkArgument( Strings.isNullOrEmpty(extra), "Extra data not expected for OAuth flow"); Preconditions.checkArgument( initialAuthData != null, "Initial auth data expected for " + config.getServiceName()); OAuthGetAccessToken accessTokenRequest = new OAuthGetAccessToken(config.getAccessTokenUrl()); accessTokenRequest.transport = httpTransport; accessTokenRequest.temporaryToken = ((TokenSecretAuthData) initialAuthData).getToken(); accessTokenRequest.consumerKey = clientId; accessTokenRequest.verifier = authCode; accessTokenRequest.signer = config.getAccessTokenSigner( clientSecret, ((TokenSecretAuthData) initialAuthData).getSecret()); TokenSecretAuthData accessToken; try { OAuthCredentialsResponse response = accessTokenRequest.execute(); accessToken = new TokenSecretAuthData(response.token, response.tokenSecret); } catch (IOException e) { monitor.severe(() -> "Error retrieving request token", e); return null; } return accessToken; }