本文整理汇总了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"));
}
}
}
}
示例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);
}
}
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
示例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() );
}