com.github.scribejava.core.model.Token Java Examples
The following examples show how to use
com.github.scribejava.core.model.Token.
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: DefaultJsonConverter.java From vertx-pac4j with Apache License 2.0 | 5 votes |
public DefaultJsonConverter() { mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE); mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE); mapper.addMixIn(OAuth1RequestToken.class, OAuth1RequestTokenMixin.class) .addMixIn(BearerAccessToken.class, BearerAccessTokenMixin.class) .addMixIn(Scope.Value.class, ValueMixin.class) .addMixIn(Token.class, TokenMixin.class); }
Example #2
Source File: OAuthBaseClient.java From android-oauth-handler with MIT License | 5 votes |
public void instantiateClient(String consumerKey, String consumerSecret, Token token) { if (token instanceof OAuth1AccessToken) { client = OAuthAsyncHttpClient.create(consumerKey, consumerSecret, (OAuth1AccessToken)(token)); } else if (token instanceof OAuth2AccessToken){ client = OAuthAsyncHttpClient.create((OAuth2AccessToken) token); } else { throw new IllegalStateException("unrecognized token type" + token); } }
Example #3
Source File: OAuthBaseClient.java From android-oauth-handler with MIT License | 5 votes |
public Token checkAccessToken() { int oAuthVersion = prefs.getInt(OAuthConstants.VERSION, 0); if (oAuthVersion == 1 && prefs.contains(OAuthConstants.TOKEN) && prefs.contains(OAuthConstants.TOKEN_SECRET)) { return new OAuth1AccessToken(prefs.getString(OAuthConstants.TOKEN, ""), prefs.getString(OAuthConstants.TOKEN_SECRET, "")); } else if (oAuthVersion == 2 && prefs.contains(OAuthConstants.TOKEN)) { return new OAuth2AccessToken(prefs.getString(OAuthConstants.TOKEN, "")); } return null; }
Example #4
Source File: OAuthBaseClient.java From android-oauth-handler with MIT License | 5 votes |
protected @Nullable Token getOAuth1RequestToken() { int oAuthVersion = prefs.getInt(OAuthConstants.VERSION, 0); if (oAuthVersion == 1) { return new OAuth1RequestToken(prefs.getString(OAUTH1_REQUEST_TOKEN, ""), prefs.getString(OAUTH1_REQUEST_TOKEN_SECRET, "")); } return null; }
Example #5
Source File: OAuthTokenClient.java From android-oauth-handler with MIT License | 5 votes |
public void setAccessToken(Token accessToken) { if (accessToken == null) { this.accessToken = null; } else { this.accessToken = accessToken; } }
Example #6
Source File: OAuthBaseClient.java From android-oauth-handler with MIT License | 4 votes |
public OAuthBaseClient(Context c, final BaseApi apiInstance, String consumerUrl, final String consumerKey, final String consumerSecret, @Nullable String scope, String callbackUrl) { this.baseUrl = consumerUrl; this.callbackUrl = callbackUrl; tokenClient = new OAuthTokenClient(apiInstance, consumerKey, consumerSecret, callbackUrl, scope, new OAuthTokenClient.OAuthTokenHandler() { // Store request token and launch the authorization URL in the browser @Override public void onReceivedRequestToken(Token requestToken, String authorizeUrl, String oAuthVersion) { if (requestToken != null) { if (oAuthVersion == OAUTH1_VERSION) { // store for OAuth1.0a OAuth1RequestToken oAuth1RequestToken = (OAuth1RequestToken) requestToken; editor.putString(OAUTH1_REQUEST_TOKEN, oAuth1RequestToken.getToken()); editor.putString(OAUTH1_REQUEST_TOKEN_SECRET, oAuth1RequestToken.getTokenSecret()); editor.putInt(OAuthConstants.VERSION, 1); editor.commit(); } } // Launch the authorization URL in the browser Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authorizeUrl)); if (requestIntentFlags != -1) { intent.setFlags(requestIntentFlags); } OAuthBaseClient.this.context.startActivity(intent); } // Store the access token in preferences, set the token in the tokenClient and fire the success callback @Override public void onReceivedAccessToken(Token accessToken, String oAuthVersion) { if (oAuthVersion == OAUTH1_VERSION) { OAuth1AccessToken oAuth1AccessToken = (OAuth1AccessToken) accessToken; tokenClient.setAccessToken(accessToken); instantiateClient(consumerKey, consumerSecret, oAuth1AccessToken); editor.putString(OAuthConstants.TOKEN, oAuth1AccessToken.getToken()); editor.putString(OAuthConstants.TOKEN_SECRET, oAuth1AccessToken.getTokenSecret()); editor.putInt(OAuthConstants.VERSION, 1); editor.commit(); } else if (oAuthVersion == OAUTH2_VERSION) { OAuth2AccessToken oAuth2AccessToken = (OAuth2AccessToken) accessToken; instantiateClient(consumerKey, consumerSecret, oAuth2AccessToken); tokenClient.setAccessToken(accessToken); editor.putString(OAuthConstants.TOKEN, oAuth2AccessToken.getAccessToken()); editor.putString(OAuthConstants.SCOPE, oAuth2AccessToken.getScope()); editor.putString(OAuthConstants.REFRESH_TOKEN, oAuth2AccessToken.getRefreshToken()); editor.putInt(OAuthConstants.VERSION, 2); editor.commit(); } accessHandler.onLoginSuccess(); } @Override public void onFailure(Exception e) { accessHandler.onLoginFailure(e); } }); this.context = c; // Store preferences namespaced by the class and consumer key used this.prefs = this.context.getSharedPreferences("OAuth_" + apiInstance.getClass().getSimpleName() + "_" + consumerKey, 0); this.editor = this.prefs.edit(); // Set access token in the tokenClient if already stored in preferences Token accessToken = this.checkAccessToken(); if (accessToken != null) { tokenClient.setAccessToken(accessToken); instantiateClient(consumerKey, consumerSecret, accessToken); } }
Example #7
Source File: OAuthTokenClient.java From android-oauth-handler with MIT License | 4 votes |
public void fetchAccessToken(final Token requestToken, final Uri uri) { Uri authorizedUri = uri; if (service.getVersion() == "1.0") { // Use verifier token to fetch access token if (authorizedUri.getQuery().contains(OAuthConstants.VERIFIER)) { String oauth_verifier = authorizedUri.getQueryParameter(OAuthConstants.VERIFIER); OAuth1RequestToken oAuth1RequestToken = (OAuth1RequestToken) requestToken; OAuth10aService oAuth10aService = (OAuth10aService) service; oAuth10aService.getAccessTokenAsync(oAuth1RequestToken, oauth_verifier, new OAuthAsyncRequestCallback<OAuth1AccessToken>() { @Override public void onCompleted(OAuth1AccessToken oAuth1AccessToken) { setAccessToken(oAuth1AccessToken); handler.onReceivedAccessToken(oAuth1AccessToken, service.getVersion()); } @Override public void onThrowable(Throwable e) { handler.onFailure(new OAuthException(e.getMessage())); } }); } else { // verifier was null throw new OAuthException("No verifier code was returned with uri '" + uri + "' " + "and access token cannot be retrieved"); } } else if (service.getVersion() == "2.0") { if (authorizedUri.getQuery().contains(OAuthConstants.CODE)) { String code = authorizedUri.getQueryParameter(OAuthConstants.CODE); OAuth20Service oAuth20Service = (OAuth20Service) service; oAuth20Service.getAccessToken(code, new OAuthAsyncRequestCallback<OAuth2AccessToken>() { @Override public void onCompleted(OAuth2AccessToken accessToken) { setAccessToken(accessToken); handler.onReceivedAccessToken(accessToken, service.getVersion()); } @Override public void onThrowable(Throwable t) { } }); } else { // verifier was null handler.onFailure(new OAuthException("No code was returned with uri '" + uri + "' " + "and access token cannot be retrieved")); } } }
Example #8
Source File: OAuthTokenClient.java From android-oauth-handler with MIT License | 4 votes |
public Token getAccessToken() { return this.accessToken; }
Example #9
Source File: OAuthTokenClient.java From android-oauth-handler with MIT License | votes |
public void onReceivedRequestToken(Token requestToken, String authorizeUrl, String oAuthVersion);
Example #10
Source File: OAuthTokenClient.java From android-oauth-handler with MIT License | votes |
public void onReceivedAccessToken(Token accessToken, String oAuthVersion);