当前位置: 首页>>代码示例>>Java>>正文


Java TokenResponseException类代码示例

本文整理汇总了Java中com.google.api.client.auth.oauth2.TokenResponseException的典型用法代码示例。如果您正苦于以下问题:Java TokenResponseException类的具体用法?Java TokenResponseException怎么用?Java TokenResponseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TokenResponseException类属于com.google.api.client.auth.oauth2包,在下文中一共展示了TokenResponseException类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doFilter

import com.google.api.client.auth.oauth2.TokenResponseException; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain filterChain) throws IOException, ServletException {

  // Skip this filter if somehow we have a request that's not HTTP
  if (response instanceof HttpServletResponse && request instanceof HttpServletRequest) {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    // Attempt to re-auth if we have an invalid grant exception.
    // This will only work if the request has not yet been committed.
    try {
      filterChain.doFilter(request, response);
    } catch (TokenResponseException e) {
      if (e.getDetails().getError().contains("invalid_grant")) {
        LOG.warning("User disabled Glassware. Attempting to re-authenticate");
        httpResponse.sendRedirect(WebUtil.buildUrl(httpRequest, "/oauth2callback"));
      }
    }
  }
}
 
开发者ID:ipool,项目名称:GlassPool,代码行数:22,代码来源:ReauthFilter.java

示例2: obtainAccessToken

import com.google.api.client.auth.oauth2.TokenResponseException; //导入依赖的package包/类
@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" + (sudoScope ? "?scope=api%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);
    }
  }
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:17,代码来源:GitLabContext.java

示例3: map

import com.google.api.client.auth.oauth2.TokenResponseException; //导入依赖的package包/类
@Override
public BackgroundException map(final TokenResponseException failure) {
    final StringBuilder buffer = new StringBuilder();
    final TokenErrorResponse details = failure.getDetails();
    if(null != details) {
        this.append(buffer, details.getErrorDescription());
    }
    return new LoginFailureException(buffer.toString(), failure);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:10,代码来源:OAuthExceptionMappingService.java

示例4: handleConflict

import com.google.api.client.auth.oauth2.TokenResponseException; //导入依赖的package包/类
@ExceptionHandler(TokenResponseException.class)
public String handleConflict(HttpServletRequest req, TokenResponseException e) throws IOException {
	if (e.getDetails().getError().contains("invalid_grant")) {
		logger.warning("User disabled OAuth 2.0 access. Attempting to re-authenticate.");
		return "redirect:" + OauthController.OAUTH_CONTROLLER_MAPPING;
	} else {
		throw e;
	}
}
 
开发者ID:jwilsoncredera,项目名称:spring-boot-glass,代码行数:10,代码来源:ControllerExceptionHandler.java

示例5: authorizeImplicitly

import com.google.api.client.auth.oauth2.TokenResponseException; //导入依赖的package包/类
/**
 * Authorizes the Android application to access user's protected data using
 * the Implicit Authorization flow in OAuth 2.0.
 * 
 * @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> authorizeImplicitly(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 TokenResponseException, Exception {
            try {
                LOGGER.info("authorizeImplicitly");
                Credential credential = mFlow.loadCredential(userId);
                if (credential != null && credential.getAccessToken() != null
                        && (credential.getRefreshToken() != null ||
                                credential.getExpiresInSeconds() == null ||
                        credential.getExpiresInSeconds() > 60)) {
                    set(credential);
                    return;
                }

                String redirectUri = mUIController.getRedirectUri();

                BrowserClientRequestUrl authorizationUrl = mFlow.newImplicitAuthorizationUrl()
                        .setRedirectUri(redirectUri);
                mUIController.requestAuthorization(authorizationUrl);

                ImplicitResponseUrl implicitResponse = mUIController
                        .waitForImplicitResponseUrl();
                credential = mFlow.createAndStoreCredential(implicitResponse, userId);
                set(credential);
            } finally {
                mUIController.stop();
            }
        }

    };

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

    return task;
}
 
开发者ID:agilie,项目名称:dribbble-android-sdk,代码行数:54,代码来源:OAuthManager.java

示例6: init

import com.google.api.client.auth.oauth2.TokenResponseException; //导入依赖的package包/类
@Override
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (GaInputStepMeta) smi;
  data = (GaInputStepData) sdi;

  if ( !super.init( smi, sdi ) ) {
    return false;
  }

  // Look for deprecated field types and log error(s) for them
  String[] types = environmentSubstitute( meta.getFeedFieldType() );
  if ( types != null ) {
    for ( String type : types ) {
      if ( GaInputStepMeta.DEPRECATED_FIELD_TYPE_CONFIDENCE_INTERVAL.equals( type ) ) {
        logError( BaseMessages.getString( PKG, "GoogleAnalytics.Warn.FieldTypeNotSupported",
          GaInputStepMeta.DEPRECATED_FIELD_TYPE_CONFIDENCE_INTERVAL ) );
      }
    }
  }

  String appName = environmentSubstitute( meta.getGaAppName() );
  String serviceAccount = environmentSubstitute( meta.getOAuthServiceAccount() );
  String OAuthKeyFile = environmentSubstitute( meta.getOAuthKeyFile() );

  if ( log.isDetailed() ) {
    logDetailed( BaseMessages.getString( PKG, "GoogleAnalyticsDialog.AppName.Label" ) + ": " + appName );
    logDetailed( BaseMessages.getString( PKG, "GoogleAnalyticsDialog.OauthAccount.Label" ) + ": " + serviceAccount );
    logDetailed( BaseMessages.getString( PKG, "GoogleAnalyticsDialog.KeyFile.Label" ) + ": " + OAuthKeyFile );
  }

  try {
    // Create an Analytics object, and fetch what we can for later (account name, e.g.)
    analytics = GoogleAnalyticsApiFacade.createFor( appName, serviceAccount, OAuthKeyFile ).getAnalytics();
    // There is necessarily an account name associated with this, so any NPEs or other exceptions mean bail out
    accountName = analytics.management().accounts().list().execute().getItems().iterator().next().getName();
  } catch ( TokenResponseException tre ) {
    Exception exceptionToLog = tre;
    if ( tre.getDetails() != null && tre.getDetails().getError() != null ) {
      exceptionToLog = new IOException( BaseMessages.getString( PKG, "GoogleAnalytics.Error.OAuth2.Auth",
          tre.getDetails().getError() ), tre );
    }
    logError( BaseMessages.getString( PKG, "GoogleAnalytics.Error.AccessingGaApi" ), exceptionToLog );
    return false;
  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "GoogleAnalytics.Error.AccessingGaApi" ), e );
    return false;
  }
  return true;
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:50,代码来源:GaInputStep.java

示例7: AuthorizationException

import com.google.api.client.auth.oauth2.TokenResponseException; //导入依赖的package包/类
/**
 * Instantiates a new Authorization exception.
 *
 * @param tokenException the TokenResponseException
 */
public AuthorizationException(TokenResponseException tokenException) {
  this( AuthorizationException.buildErrors( tokenException.getDetails() ), tokenException.getStatusCode() );
}
 
开发者ID:icoretech,项目名称:audiobox-jlib,代码行数:9,代码来源:AuthorizationException.java


注:本文中的com.google.api.client.auth.oauth2.TokenResponseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。