Class OAuth2SessionRef
java.lang.Object
com.peterphi.std.guice.web.rest.auth.oauth2.OAuth2SessionRef
Holds the OAuth2 callback information for this session; will start unpopulated (see
isValid()
) and then be populated
once the OAuth2 callback completes. It will switch back to unpopulated when the OAuth2 session expires.
While populated the session ref can be used to query for the currently active token
assigned by the server, as
well as querying side-channel information on the user associated with that token (when the OAuth2 provider is the User
Manager)
-
Field Summary
Modifier and TypeFieldDescriptionboolean
final UserManagerOAuthService
final String
final String
org.joda.time.Period
-
Constructor Summary
ConstructorDescriptionOAuth2SessionRef
(UserManagerOAuthService authService, String oauthServiceEndpoint, String clientId, String clientSecret, URI localEndpoint) -
Method Summary
Modifier and TypeMethodDescriptiongetAuthFlowStartEndpoint
(String returnTo, String scope) Get the endpoint to redirect a client to in order to start an OAuth2 Authorisation FlowReturn the URI for this service's callback resourcegetRedirectToFromState
(String state) Decode the state to retrieve the redirectTo valuestatic URI
Gets the URI the user should GET for the redirect.getToken()
boolean
void
initialiseFromAPIToken
(String token) Initialise this session reference by exchanging an API token for an access_token and refresh_tokenboolean
isValid()
void
load
(OAuth2TokenResponse response) protected void
loadAuthResponse
(String responseStr) void
Use the refresh token to get a new token with a longer lifespanvoid
boolean
-
Field Details
-
authService
-
oauthServiceEndpoint
-
oauthServiceRedirectEndpoint
-
oauthSelfEndpoint
-
tokenRefreshPriorToExpire
@Inject(optional=true) public org.joda.time.Period tokenRefreshPriorToExpire -
delegatedTokenValidityPeriod
-
delegatedTokenRefreshPeriod
-
allowDelegatedTokenGeneration
@Inject(optional=true) public boolean allowDelegatedTokenGeneration -
clientId
-
-
Constructor Details
-
OAuth2SessionRef
@Inject public OAuth2SessionRef(UserManagerOAuthService authService, String oauthServiceEndpoint, String clientId, String clientSecret, URI localEndpoint)
-
-
Method Details
-
hasBeenInitialised
public boolean hasBeenInitialised() -
initialiseFromAPIToken
Initialise this session reference by exchanging an API token for an access_token and refresh_token- Parameters:
token
-
-
isValid
public boolean isValid() -
getOwnCallbackUri
Return the URI for this service's callback resource- Returns:
-
getAuthFlowStartEndpoint
Get the endpoint to redirect a client to in order to start an OAuth2 Authorisation Flow- Parameters:
returnTo
- The URI to redirect the user back to once the authorisation flow completes successfully. If not specified then the user will be directed to the root of this webapp.- Returns:
-
getRedirectToFromState
Decode the state to retrieve the redirectTo value- Parameters:
state
-- Returns:
-
getRedirectToFromStateIgnoringNonce
Gets the URI the user should GET for the redirect. N.B. fails on anything other than GET.- Parameters:
state
-- Returns:
-
shouldRefresh
public boolean shouldRefresh() -
getToken
-
refreshToken
public void refreshToken()Use the refresh token to get a new token with a longer lifespan -
loadAuthResponse
-
refreshUserInfo
public void refreshUserInfo() -
getUserInfo
-
load
-
getOrCreateDelegatedToken
-