Package com.github.scribejava.core.oauth
Class OAuth20Service
java.lang.Object
com.github.scribejava.core.oauth.OAuthService
com.github.scribejava.core.oauth.OAuth20Service
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class OAuth20Service extends OAuthService
-
Constructor Summary
Constructors Constructor Description OAuth20Service(DefaultApi20 api, java.lang.String apiKey, java.lang.String apiSecret, java.lang.String callback, java.lang.String defaultScope, java.lang.String responseType, java.io.OutputStream debugStream, java.lang.String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient)
-
Method Summary
Modifier and Type Method Description protected OAuthRequest
createAccessTokenClientCredentialsGrantRequest(java.lang.String scope)
protected OAuthRequest
createAccessTokenDeviceAuthorizationGrantRequest(DeviceAuthorization deviceAuthorization)
protected OAuthRequest
createAccessTokenPasswordGrantRequest(java.lang.String username, java.lang.String password, java.lang.String scope)
protected OAuthRequest
createAccessTokenRequest(AccessTokenRequestParams params)
AuthorizationUrlBuilder
createAuthorizationUrlBuilder()
protected OAuthRequest
createDeviceAuthorizationCodesRequest(java.lang.String scope)
protected OAuthRequest
createRefreshTokenRequest(java.lang.String refreshToken, java.lang.String scope)
protected OAuthRequest
createRevokeTokenRequest(java.lang.String tokenToRevoke, TokenTypeHint tokenTypeHint)
OAuth2Authorization
extractAuthorization(java.lang.String redirectLocation)
OAuth2AccessToken
getAccessToken(AccessTokenRequestParams params)
java.util.concurrent.Future<OAuth2AccessToken>
getAccessToken(AccessTokenRequestParams params, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
Start the request to retrieve the access token.OAuth2AccessToken
getAccessToken(java.lang.String code)
java.util.concurrent.Future<OAuth2AccessToken>
getAccessToken(java.lang.String code, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenAsync(AccessTokenRequestParams params)
java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenAsync(java.lang.String code)
OAuth2AccessToken
getAccessTokenClientCredentialsGrant()
java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenClientCredentialsGrant(OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
Start the request to retrieve the access token using client-credentials grant.OAuth2AccessToken
getAccessTokenClientCredentialsGrant(java.lang.String scope)
java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenClientCredentialsGrant(java.lang.String scope, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenClientCredentialsGrantAsync()
java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenClientCredentialsGrantAsync(java.lang.String scope)
OAuth2AccessToken
getAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization)
Attempts to get a token from a server.java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenDeviceAuthorizationGrantAsync(DeviceAuthorization deviceAuthorization)
OAuth2AccessToken
getAccessTokenPasswordGrant(java.lang.String username, java.lang.String password)
OAuth2AccessToken
getAccessTokenPasswordGrant(java.lang.String username, java.lang.String password, java.lang.String scope)
java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenPasswordGrantAsync(java.lang.String username, java.lang.String password)
java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenPasswordGrantAsync(java.lang.String username, java.lang.String password, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
Request Access Token Password Grant async versionjava.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenPasswordGrantAsync(java.lang.String username, java.lang.String password, java.lang.String scope)
java.util.concurrent.Future<OAuth2AccessToken>
getAccessTokenPasswordGrantAsync(java.lang.String username, java.lang.String password, java.lang.String scope, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
DefaultApi20
getApi()
java.lang.String
getAuthorizationUrl()
Returns the URL where you should redirect your users to authenticate your application.java.lang.String
getAuthorizationUrl(PKCE pkce)
java.lang.String
getAuthorizationUrl(java.lang.String state)
java.lang.String
getAuthorizationUrl(java.util.Map<java.lang.String,java.lang.String> additionalParams)
Returns the URL where you should redirect your users to authenticate your application.java.lang.String
getDefaultScope()
DeviceAuthorization
getDeviceAuthorizationCodes()
Requests a set of verification codes from the authorization server with the default scopejava.util.concurrent.Future<DeviceAuthorization>
getDeviceAuthorizationCodes(OAuthAsyncRequestCallback<DeviceAuthorization> callback)
DeviceAuthorization
getDeviceAuthorizationCodes(java.lang.String scope)
Requests a set of verification codes from the authorization serverjava.util.concurrent.Future<DeviceAuthorization>
getDeviceAuthorizationCodes(java.lang.String scope, OAuthAsyncRequestCallback<DeviceAuthorization> callback)
java.util.concurrent.Future<DeviceAuthorization>
getDeviceAuthorizationCodesAsync()
java.util.concurrent.Future<DeviceAuthorization>
getDeviceAuthorizationCodesAsync(java.lang.String scope)
java.lang.String
getResponseType()
java.lang.String
getVersion()
Returns the OAuth version of the service.OAuth2AccessToken
pollAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization)
Periodically tries to get a token from a server (waiting for the user to give consent).OAuth2AccessToken
refreshAccessToken(java.lang.String refreshToken)
java.util.concurrent.Future<OAuth2AccessToken>
refreshAccessToken(java.lang.String refreshToken, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
OAuth2AccessToken
refreshAccessToken(java.lang.String refreshToken, java.lang.String scope)
java.util.concurrent.Future<OAuth2AccessToken>
refreshAccessToken(java.lang.String refreshToken, java.lang.String scope, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
java.util.concurrent.Future<OAuth2AccessToken>
refreshAccessTokenAsync(java.lang.String refreshToken)
java.util.concurrent.Future<OAuth2AccessToken>
refreshAccessTokenAsync(java.lang.String refreshToken, java.lang.String scope)
void
revokeToken(java.lang.String tokenToRevoke)
java.util.concurrent.Future<java.lang.Void>
revokeToken(java.lang.String tokenToRevoke, OAuthAsyncRequestCallback<java.lang.Void> callback)
java.util.concurrent.Future<java.lang.Void>
revokeToken(java.lang.String tokenToRevoke, OAuthAsyncRequestCallback<java.lang.Void> callback, TokenTypeHint tokenTypeHint)
void
revokeToken(java.lang.String tokenToRevoke, TokenTypeHint tokenTypeHint)
java.util.concurrent.Future<java.lang.Void>
revokeTokenAsync(java.lang.String tokenToRevoke)
java.util.concurrent.Future<java.lang.Void>
revokeTokenAsync(java.lang.String tokenToRevoke, TokenTypeHint tokenTypeHint)
protected java.util.concurrent.Future<OAuth2AccessToken>
sendAccessTokenRequestAsync(OAuthRequest request)
protected java.util.concurrent.Future<OAuth2AccessToken>
sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)
protected OAuth2AccessToken
sendAccessTokenRequestSync(OAuthRequest request)
void
signRequest(OAuth2AccessToken accessToken, OAuthRequest request)
void
signRequest(java.lang.String accessToken, OAuthRequest request)
Methods inherited from class com.github.scribejava.core.oauth.OAuthService
close, execute, execute, execute, executeAsync, getApiKey, getApiSecret, getCallback, isDebug, log, log
-
Constructor Details
-
OAuth20Service
public OAuth20Service(DefaultApi20 api, java.lang.String apiKey, java.lang.String apiSecret, java.lang.String callback, java.lang.String defaultScope, java.lang.String responseType, java.io.OutputStream debugStream, java.lang.String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient)
-
-
Method Details
-
sendAccessTokenRequestSync
protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
sendAccessTokenRequestAsync
protected java.util.concurrent.Future<OAuth2AccessToken> sendAccessTokenRequestAsync(OAuthRequest request) -
sendAccessTokenRequestAsync
protected java.util.concurrent.Future<OAuth2AccessToken> sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback<OAuth2AccessToken> callback) -
getAccessTokenAsync
-
getAccessTokenAsync
public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenAsync(AccessTokenRequestParams params) -
getAccessToken
public OAuth2AccessToken getAccessToken(java.lang.String code) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
getAccessToken
public OAuth2AccessToken getAccessToken(AccessTokenRequestParams params) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
getAccessToken
public java.util.concurrent.Future<OAuth2AccessToken> getAccessToken(AccessTokenRequestParams params, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)Start the request to retrieve the access token. The optionally provided callback will be called with the Token when it is available.- Parameters:
params
- paramscallback
- optional callback- Returns:
- Future
-
getAccessToken
public java.util.concurrent.Future<OAuth2AccessToken> getAccessToken(java.lang.String code, OAuthAsyncRequestCallback<OAuth2AccessToken> callback) -
createAccessTokenRequest
-
refreshAccessTokenAsync
public java.util.concurrent.Future<OAuth2AccessToken> refreshAccessTokenAsync(java.lang.String refreshToken) -
refreshAccessTokenAsync
public java.util.concurrent.Future<OAuth2AccessToken> refreshAccessTokenAsync(java.lang.String refreshToken, java.lang.String scope) -
refreshAccessToken
public OAuth2AccessToken refreshAccessToken(java.lang.String refreshToken) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
refreshAccessToken
public OAuth2AccessToken refreshAccessToken(java.lang.String refreshToken, java.lang.String scope) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
refreshAccessToken
public java.util.concurrent.Future<OAuth2AccessToken> refreshAccessToken(java.lang.String refreshToken, OAuthAsyncRequestCallback<OAuth2AccessToken> callback) -
refreshAccessToken
public java.util.concurrent.Future<OAuth2AccessToken> refreshAccessToken(java.lang.String refreshToken, java.lang.String scope, OAuthAsyncRequestCallback<OAuth2AccessToken> callback) -
createRefreshTokenRequest
protected OAuthRequest createRefreshTokenRequest(java.lang.String refreshToken, java.lang.String scope) -
getAccessTokenPasswordGrant
public OAuth2AccessToken getAccessTokenPasswordGrant(java.lang.String username, java.lang.String password) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
getAccessTokenPasswordGrant
public OAuth2AccessToken getAccessTokenPasswordGrant(java.lang.String username, java.lang.String password, java.lang.String scope) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
getAccessTokenPasswordGrantAsync
public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync(java.lang.String username, java.lang.String password) -
getAccessTokenPasswordGrantAsync
public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync(java.lang.String username, java.lang.String password, java.lang.String scope) -
getAccessTokenPasswordGrantAsync
public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync(java.lang.String username, java.lang.String password, OAuthAsyncRequestCallback<OAuth2AccessToken> callback)Request Access Token Password Grant async version- Parameters:
username
- User namepassword
- User passwordcallback
- Optional callback- Returns:
- Future
-
getAccessTokenPasswordGrantAsync
public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenPasswordGrantAsync(java.lang.String username, java.lang.String password, java.lang.String scope, OAuthAsyncRequestCallback<OAuth2AccessToken> callback) -
createAccessTokenPasswordGrantRequest
protected OAuthRequest createAccessTokenPasswordGrantRequest(java.lang.String username, java.lang.String password, java.lang.String scope) -
getAccessTokenClientCredentialsGrantAsync
-
getAccessTokenClientCredentialsGrantAsync
public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenClientCredentialsGrantAsync(java.lang.String scope) -
getAccessTokenClientCredentialsGrant
public OAuth2AccessToken getAccessTokenClientCredentialsGrant() throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
getAccessTokenClientCredentialsGrant
public OAuth2AccessToken getAccessTokenClientCredentialsGrant(java.lang.String scope) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
getAccessTokenClientCredentialsGrant
public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenClientCredentialsGrant(OAuthAsyncRequestCallback<OAuth2AccessToken> callback)Start the request to retrieve the access token using client-credentials grant. The optionally provided callback will be called with the Token when it is available.- Parameters:
callback
- optional callback- Returns:
- Future
-
getAccessTokenClientCredentialsGrant
public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenClientCredentialsGrant(java.lang.String scope, OAuthAsyncRequestCallback<OAuth2AccessToken> callback) -
createAccessTokenClientCredentialsGrantRequest
-
getVersion
public java.lang.String getVersion()Returns the OAuth version of the service.- Specified by:
getVersion
in classOAuthService
- Returns:
- OAuth version as string
-
signRequest
-
signRequest
-
getAuthorizationUrl
public java.lang.String getAuthorizationUrl()Returns the URL where you should redirect your users to authenticate your application.- Returns:
- the URL where you should redirect your users
-
getAuthorizationUrl
public java.lang.String getAuthorizationUrl(java.lang.String state) -
getAuthorizationUrl
public java.lang.String getAuthorizationUrl(java.util.Map<java.lang.String,java.lang.String> additionalParams)Returns the URL where you should redirect your users to authenticate your application.- Parameters:
additionalParams
- any additional GET params to add to the URL- Returns:
- the URL where you should redirect your users
-
getAuthorizationUrl
-
createAuthorizationUrlBuilder
-
getApi
-
createRevokeTokenRequest
protected OAuthRequest createRevokeTokenRequest(java.lang.String tokenToRevoke, TokenTypeHint tokenTypeHint) -
revokeTokenAsync
public java.util.concurrent.Future<java.lang.Void> revokeTokenAsync(java.lang.String tokenToRevoke) -
revokeTokenAsync
public java.util.concurrent.Future<java.lang.Void> revokeTokenAsync(java.lang.String tokenToRevoke, TokenTypeHint tokenTypeHint) -
revokeToken
public void revokeToken(java.lang.String tokenToRevoke) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
revokeToken
public void revokeToken(java.lang.String tokenToRevoke, TokenTypeHint tokenTypeHint) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.ExecutionException- Throws:
java.io.IOException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
revokeToken
public java.util.concurrent.Future<java.lang.Void> revokeToken(java.lang.String tokenToRevoke, OAuthAsyncRequestCallback<java.lang.Void> callback) -
revokeToken
public java.util.concurrent.Future<java.lang.Void> revokeToken(java.lang.String tokenToRevoke, OAuthAsyncRequestCallback<java.lang.Void> callback, TokenTypeHint tokenTypeHint) -
extractAuthorization
-
getResponseType
public java.lang.String getResponseType() -
getDefaultScope
public java.lang.String getDefaultScope() -
createDeviceAuthorizationCodesRequest
-
getDeviceAuthorizationCodes
public DeviceAuthorization getDeviceAuthorizationCodes() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOExceptionRequests a set of verification codes from the authorization server with the default scope- Returns:
- DeviceAuthorization
- Throws:
java.lang.InterruptedException
- InterruptedExceptionjava.util.concurrent.ExecutionException
- ExecutionExceptionjava.io.IOException
- IOException- See Also:
- RFC 8628
-
getDeviceAuthorizationCodes
public DeviceAuthorization getDeviceAuthorizationCodes(java.lang.String scope) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOExceptionRequests a set of verification codes from the authorization server- Parameters:
scope
- scope- Returns:
- DeviceAuthorization
- Throws:
java.lang.InterruptedException
- InterruptedExceptionjava.util.concurrent.ExecutionException
- ExecutionExceptionjava.io.IOException
- IOException- See Also:
- RFC 8628
-
getDeviceAuthorizationCodes
public java.util.concurrent.Future<DeviceAuthorization> getDeviceAuthorizationCodes(OAuthAsyncRequestCallback<DeviceAuthorization> callback) -
getDeviceAuthorizationCodes
public java.util.concurrent.Future<DeviceAuthorization> getDeviceAuthorizationCodes(java.lang.String scope, OAuthAsyncRequestCallback<DeviceAuthorization> callback) -
getDeviceAuthorizationCodesAsync
-
getDeviceAuthorizationCodesAsync
public java.util.concurrent.Future<DeviceAuthorization> getDeviceAuthorizationCodesAsync(java.lang.String scope) -
createAccessTokenDeviceAuthorizationGrantRequest
protected OAuthRequest createAccessTokenDeviceAuthorizationGrantRequest(DeviceAuthorization deviceAuthorization) -
getAccessTokenDeviceAuthorizationGrant
public OAuth2AccessToken getAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOExceptionAttempts to get a token from a server. FunctionpollAccessTokenDeviceAuthorizationGrant(com.github.scribejava.core.model.DeviceAuthorization)
is usually used instead of this.- Parameters:
deviceAuthorization
- deviceAuthorization- Returns:
- token
- Throws:
java.lang.InterruptedException
- InterruptedExceptionjava.util.concurrent.ExecutionException
- ExecutionExceptionjava.io.IOException
- IOExceptionOAuth2AccessTokenErrorResponse
- IfOAuth2AccessTokenErrorResponse.getError()
isOAuth2Error.AUTHORIZATION_PENDING
orOAuth2Error.SLOW_DOWN
, another attempt should be made after a while.- See Also:
getDeviceAuthorizationCodes()
-
getAccessTokenDeviceAuthorizationGrant
public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization, OAuthAsyncRequestCallback<OAuth2AccessToken> callback) -
getAccessTokenDeviceAuthorizationGrantAsync
public java.util.concurrent.Future<OAuth2AccessToken> getAccessTokenDeviceAuthorizationGrantAsync(DeviceAuthorization deviceAuthorization) -
pollAccessTokenDeviceAuthorizationGrant
public OAuth2AccessToken pollAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOExceptionPeriodically tries to get a token from a server (waiting for the user to give consent). Sync only version. No Async variants yet, one should implement async scenarios themselves.- Parameters:
deviceAuthorization
- deviceAuthorization- Returns:
- token
- Throws:
java.lang.InterruptedException
- InterruptedExceptionjava.util.concurrent.ExecutionException
- ExecutionExceptionjava.io.IOException
- IOExceptionOAuth2AccessTokenErrorResponse
- Indicates OAuth error.- See Also:
getDeviceAuthorizationCodes()
-