com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl Java Examples

The following examples show how to use com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl. 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: OAuth1DataGenerator.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
@Override
public AuthFlowConfiguration generateConfiguration(String callbackBaseUrl, String id) {
  String callback =
      (Strings.isNullOrEmpty(callbackBaseUrl)) ? OUT_OF_BOUNDS_CALLBACK : callbackBaseUrl;
  OAuthGetTemporaryToken tempTokenRequest =
      new OAuthGetTemporaryToken(config.getRequestTokenUrl());
  tempTokenRequest.callback = callback;
  tempTokenRequest.transport = httpTransport;
  tempTokenRequest.consumerKey = clientId;
  tempTokenRequest.signer = config.getRequestTokenSigner(clientSecret);
  if (config.whenAddScopes() == OAuth1Step.REQUEST_TOKEN) {
    tempTokenRequest.set(config.getScopeParameterName(), scope);
  }
  TokenSecretAuthData authData;
  try {
    // get request token
    OAuthCredentialsResponse tempTokenResponse = tempTokenRequest.execute();
    authData = new TokenSecretAuthData(tempTokenResponse.token, tempTokenResponse.tokenSecret);
  } catch (IOException e) {
    monitor.severe(() -> "Error retrieving request token", e);
    return null;
  }

  OAuthAuthorizeTemporaryTokenUrl authorizeUrl =
      new OAuthAuthorizeTemporaryTokenUrl(config.getAuthorizationUrl());
  authorizeUrl.temporaryToken = authData.getToken();
  if (config.whenAddScopes() == OAuth1Step.AUTHORIZATION) {
    authorizeUrl.set(config.getScopeParameterName(), scope);
  }
  String url = authorizeUrl.build();

  return new AuthFlowConfiguration(url, getTokenUrl(), AuthProtocol.OAUTH_1, authData);
}
 
Example #2
Source File: OAuthHmacThreeLeggedFlow.java    From google-oauth-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Create an OAuthThreeLeggedFlow instance from the required information.
 *
 * @param userId Key that can be used to associate this flow with an end user.
 * @param consumerKey Key that identifies the server to the service provider.
 * @param consumerSecret Secret that is shared between the server and the service provider.
 * @param authorizationServerUrl Url with which we communicate to authorize tis application.
 * @param temporaryTokenUrl Url which we will use to obtain a temporary token.
 * @param callbackUrl Url which the server should redirect the user to after obtaining
 *        authorization.
 *
 * @throws IOException Exception thrown when the flow is unable to communicate with the service
 *         provider.
 */
public OAuthHmacThreeLeggedFlow(String userId,
    String consumerKey,
    String consumerSecret,
    String authorizationServerUrl,
    String temporaryTokenUrl,
    String callbackUrl,
    HttpTransport transport) throws IOException {

  this.userId = userId;
  this.consumerSecret = consumerSecret;
  this.consumerKey = consumerKey;
  this.transport = transport;
  this.authorizationServerUrl = authorizationServerUrl;

  OAuthGetTemporaryToken temporaryToken = new OAuthGetTemporaryToken(callbackUrl);
  OAuthHmacSigner signer = new OAuthHmacSigner();
  signer.clientSharedSecret = consumerSecret;
  temporaryToken.signer = signer;
  temporaryToken.consumerKey = consumerKey;
  temporaryToken.callback = callbackUrl;
  temporaryToken.transport = this.transport;

  OAuthCredentialsResponse tempCredentials = temporaryToken.execute();

  tempToken = tempCredentials.token;
  tempTokenSecret = tempCredentials.tokenSecret;

  OAuthAuthorizeTemporaryTokenUrl authorizeUrl =
      new OAuthAuthorizeTemporaryTokenUrl(temporaryTokenUrl);
  authorizeUrl.temporaryToken = tempCredentials.token;
  this.authorizationUrl = authorizeUrl.build();
}
 
Example #3
Source File: OAuthManager.java    From android-oauth-client with Apache License 2.0 4 votes vote down vote up
/**
 * Authorizes the Android application to access user's protected data using
 * the authorization flow in OAuth 1.0a.
 * 
 * @param userId user ID or {@code null} if not using a persisted credential
 *            store
 * @param callback Callback to invoke when the request completes,
 *            {@code null} for no callback
 * @param handler {@link Handler} identifying the callback thread,
 *            {@code null} for the main thread
 * @return An {@link OAuthFuture} which resolves to a {@link Credential}
 */
public OAuthFuture<Credential> authorize10a(final String userId,
        final OAuthCallback<Credential> callback, Handler handler) {
    Preconditions.checkNotNull(userId);

    final Future2Task<Credential> task = new Future2Task<Credential>(handler, callback) {

        @Override
        public void doWork() throws Exception {
            try {
                LOGGER.info("authorize10a");
                OAuthHmacCredential credential = mFlow.load10aCredential(userId);
                if (credential != null && credential.getAccessToken() != null
                        && (credential.getRefreshToken() != null
                                || credential.getExpiresInSeconds() == null
                                || credential.getExpiresInSeconds() > 60)) {
                    set(credential);
                    return;
                }

                String redirectUri = mUIController.getRedirectUri();

                OAuthCredentialsResponse tempCredentials =
                        mFlow.new10aTemporaryTokenRequest(redirectUri);
                OAuthAuthorizeTemporaryTokenUrl authorizationUrl =
                        mFlow.new10aAuthorizationUrl(tempCredentials.token);
                mUIController.requestAuthorization(authorizationUrl);

                String code = mUIController.waitForVerifierCode();
                OAuthCredentialsResponse response =
                        mFlow.new10aTokenRequest(tempCredentials, code).execute();
                credential = mFlow.createAndStoreCredential(response, userId);
                set(credential);
            } finally {
                mUIController.stop();
            }
        }

    };

    // run the task in a background thread
    submitTaskToExecutor(task);

    return task;
}
 
Example #4
Source File: DialogFragmentController.java    From android-oauth-client with Apache License 2.0 4 votes vote down vote up
@Override
public void requestAuthorization(OAuthAuthorizeTemporaryTokenUrl authorizationRequestUrl) {
    internalRequestAuthorization(authorizationRequestUrl);
}
 
Example #5
Source File: OAuthDialogFragment.java    From android-oauth-client with Apache License 2.0 4 votes vote down vote up
@TargetApi(HONEYCOMB)
public static final OAuthDialogFragment newInstance(
        GenericUrl authorizationRequestUrl,
        DialogFragmentController controller) {
    Bundle args = new Bundle();
    args.putString(ARG_AUTHORIZATION_REQUEST_URL, authorizationRequestUrl.build());
    if (authorizationRequestUrl instanceof OAuthAuthorizeTemporaryTokenUrl) {
        args.putString(ARG_AUTHORIZATION_TYPE, AUTHORIZATION_10A);
    } else if (authorizationRequestUrl instanceof AuthorizationCodeRequestUrl) {
        args.putString(ARG_AUTHORIZATION_TYPE, AUTHORIZATION_EXPLICIT);
    } else {
        args.putString(ARG_AUTHORIZATION_TYPE, AUTHORIZATION_IMPLICIT);
    }
    BaseDialogFragmentImpl fragImpl;
    OAuthDialogFragment frag;
    if (controller.getFragmentManager() instanceof android.support.v4.app.FragmentManager) {
        fragImpl = new SupportDialogFragmentImpl();
        frag = new OAuthDialogFragment((android.support.v4.app.DialogFragment) fragImpl,
            controller.fullScreen, controller.horizontalProgress, controller.hideFullScreenTitle);
        if (controller.hideFullScreenTitle) {
            if (SDK_INT >= ICE_CREAM_SANDWICH) {
                ((android.support.v4.app.DialogFragment) fragImpl).setStyle(android.support
                        .v4.app.DialogFragment.STYLE_NORMAL,
                    android.R.style.Theme_Holo_Light_NoActionBar_Fullscreen
                );
            } else {
                ((android.support.v4.app.DialogFragment) fragImpl).setStyle(android.support
                        .v4.app.DialogFragment.STYLE_NORMAL,
                    android.R.style.Theme_Black_NoTitleBar_Fullscreen
                );
            }
        }
    } else {
        fragImpl = new NativeDialogFragmentImpl();
        frag = new OAuthDialogFragment((android.app.DialogFragment) fragImpl,
            controller.fullScreen, controller.horizontalProgress, controller.hideFullScreenTitle);
        if (controller.hideFullScreenTitle) {
            if (SDK_INT >= ICE_CREAM_SANDWICH) {
                ((android.app.DialogFragment) fragImpl).setStyle(DialogFragment.STYLE_NORMAL,
                    android.R.style.Theme_Holo_Light_NoActionBar_Fullscreen);
            } else {
                ((android.app.DialogFragment) fragImpl).setStyle(DialogFragment.STYLE_NORMAL,
                    android.R.style.Theme_Black_NoTitleBar_Fullscreen);
            }
        }
    }
    fragImpl.setDialogFragmentCompat(frag);
    frag.setArguments(args);
    frag.setController(controller);
    return frag;
}
 
Example #6
Source File: AuthorizationFlow.java    From android-oauth-client with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a new instance of a temporary token authorization request URL as
 * defined in <a
 * href="http://oauth.net/core/1.0a/#rfc.section.6.2.1">Consumer Directs the
 * User to the Service Provider</a>.
 * 
 * @param temporaryToken
 * @return
 */
public OAuthAuthorizeTemporaryTokenUrl new10aAuthorizationUrl(String temporaryToken) {
    OAuthAuthorizeTemporaryTokenUrl authorizationUrl =
            new OAuthAuthorizeTemporaryTokenUrl(getAuthorizationServerEncodedUrl());
    authorizationUrl.temporaryToken = temporaryToken;
    return authorizationUrl;
}
 
Example #7
Source File: AuthorizationUIController.java    From android-oauth-client with Apache License 2.0 2 votes vote down vote up
/**
 * Handles user authorization by redirecting to the OAuth 1.0a authorization
 * server as defined in <a
 * href="http://oauth.net/core/1.0a/#auth_step2">Obtaining User
 * Authorization</a>.
 * 
 * @param authorizationRequestUrl
 */
void requestAuthorization(OAuthAuthorizeTemporaryTokenUrl authorizationRequestUrl);