Package io.meeds.oauth.google
Class GoogleProcessorImpl
java.lang.Object
io.meeds.oauth.google.GoogleProcessorImpl
- All Implemented Interfaces:
GoogleProcessor,OAuthProviderProcessor<GoogleAccessTokenContext>
- Author:
- Marek Posolda
-
Constructor Summary
ConstructorsConstructorDescriptionGoogleProcessorImpl(org.exoplatform.container.ExoContainerContext context, org.exoplatform.container.xml.InitParams params, org.exoplatform.web.security.security.SecureRandomService secureRandomService) -
Method Summary
Modifier and TypeMethodDescriptiongetAccessTokenFromUserProfile(org.exoplatform.services.organization.UserProfile userProfile, OAuthCodec codec) Obtain needed data from given userProfile and create accessToken from them<C> CgetAuthorizedSocialApiObject(GoogleAccessTokenContext accessToken, Class<C> socialApiObjectType) Return object, which can be used to call some operations on this Social network.com.google.api.services.oauth2.Oauth2getOAuth2Instance(GoogleAccessTokenContext accessTokenContext) Obtain instance of GoogleOauth2object, which can be used to call various operations in Google API (obtain user informations, obtain informations about your access token etc)protected com.google.api.services.oauth2.Oauth2getOAuth2InstanceImpl(com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse tokenData) com.google.api.services.plus.PlusgetPlusService(GoogleAccessTokenContext accessTokenContext) Obtain instance of Google (@link Plus} object, which can be used to call various operations in Google+ API (Obtain list of your friends, obtain your statuses, comments, activities etc...)protected InteractionState<GoogleAccessTokenContext>initialInteraction(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Set<String> scopes) protected com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponseobtainAccessToken(jakarta.servlet.http.HttpServletRequest request) com.google.api.services.oauth2.model.UserinfoobtainUserInfo(GoogleAccessTokenContext accessTokenContext) Obtain informations about user from Google+ .processOAuthInteraction(jakarta.servlet.http.HttpServletRequest httpRequest, jakarta.servlet.http.HttpServletResponse httpResponse) Process OAuth workflow for this OAuth provider (social network).processOAuthInteraction(jakarta.servlet.http.HttpServletRequest httpRequest, jakarta.servlet.http.HttpServletResponse httpResponse, String scope) Possibility to create new OAuth interaction with custom scope (not just the scope which is provided in configuration of this OAuth processor)protected InteractionState<GoogleAccessTokenContext>processOAuthInteractionImpl(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Set<String> scopes) voidrefreshToken(GoogleAccessTokenContext accessTokenContext) Refresh Google+ token.voidremoveAccessTokenFromUserProfile(org.exoplatform.services.organization.UserProfile userProfile) Remove data about access token from this user profilevoidrevokeToken(GoogleAccessTokenContext accessTokenContext) Revoke given access token on OAuth provider side, so application is removed from list of supported applications for given uservoidsaveAccessTokenAttributesToUserProfile(org.exoplatform.services.organization.UserProfile userProfile, OAuthCodec codec, GoogleAccessTokenContext accessToken) Save accessToken data to given userProfile.validateTokenAndUpdateScopes(GoogleAccessTokenContext accessTokenContext) Send request to OAuth Provider to validate if given access token is valid and ask for scopes, which are available for given accessToken.
-
Constructor Details
-
GoogleProcessorImpl
public GoogleProcessorImpl(org.exoplatform.container.ExoContainerContext context, org.exoplatform.container.xml.InitParams params, org.exoplatform.web.security.security.SecureRandomService secureRandomService)
-
-
Method Details
-
processOAuthInteraction
public InteractionState<GoogleAccessTokenContext> processOAuthInteraction(jakarta.servlet.http.HttpServletRequest httpRequest, jakarta.servlet.http.HttpServletResponse httpResponse) throws IOException, OAuthException Description copied from interface:OAuthProviderProcessorProcess OAuth workflow for this OAuth provider (social network). Workflow is finished if returnedInteractionStateis in stateInteractionState.State.FINISHand in this case, InteractionState should also have accessToken filled. IfInteractionStateis in stateInteractionState.State.AUTH, then more redirections are needed. In this case, givenHttpServletResponseshould be already committed and prepared for redirection.- Specified by:
processOAuthInteractionin interfaceOAuthProviderProcessor<GoogleAccessTokenContext>- Returns:
- InteractionState with state of OAuth interaction
- Throws:
IOException- if IO error occured (for example if httpResponse.sendRedirect failed)OAuthException- in case of some other error, which may be specific for this OAuth processor (Details are available in error code) Caller should be able to handle at leastOAuthExceptionCode.USER_DENIED_SCOPEwhich happens when user denied scope (authorization screen in web of given social network)
-
processOAuthInteraction
public InteractionState<GoogleAccessTokenContext> processOAuthInteraction(jakarta.servlet.http.HttpServletRequest httpRequest, jakarta.servlet.http.HttpServletResponse httpResponse, String scope) throws IOException, OAuthException Description copied from interface:OAuthProviderProcessorPossibility to create new OAuth interaction with custom scope (not just the scope which is provided in configuration of this OAuth processor)- Specified by:
processOAuthInteractionin interfaceOAuthProviderProcessor<GoogleAccessTokenContext>scope- custom scope, which contains all scopes in single String divided byAccessTokenContext.DELIMITER- Returns:
- Throws:
IOExceptionOAuthException- See Also:
-
processOAuthInteractionImpl
protected InteractionState<GoogleAccessTokenContext> processOAuthInteractionImpl(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Set<String> scopes) throws IOException - Throws:
IOException
-
initialInteraction
protected InteractionState<GoogleAccessTokenContext> initialInteraction(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Set<String> scopes) throws IOException - Throws:
IOException
-
obtainAccessToken
protected com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse obtainAccessToken(jakarta.servlet.http.HttpServletRequest request) throws IOException - Throws:
IOException
-
validateTokenAndUpdateScopes
public GoogleAccessTokenContext validateTokenAndUpdateScopes(GoogleAccessTokenContext accessTokenContext) Description copied from interface:OAuthProviderProcessorSend request to OAuth Provider to validate if given access token is valid and ask for scopes, which are available for given accessToken. Returned access token should be always valid and prepared for invoke other operations- Specified by:
validateTokenAndUpdateScopesin interfaceOAuthProviderProcessor<GoogleAccessTokenContext>- Parameters:
accessTokenContext- accessToken which will be used to ask OAuthProvider about validation and for available scopes- Returns:
- accessTokenContext, which will be quite same as the one from accessToken parameter. It could have some info updated (like scopes)
-
getAuthorizedSocialApiObject
public <C> C getAuthorizedSocialApiObject(GoogleAccessTokenContext accessToken, Class<C> socialApiObjectType) Description copied from interface:OAuthProviderProcessorReturn object, which can be used to call some operations on this Social network. For example "Plus" object for Google+ network- Specified by:
getAuthorizedSocialApiObjectin interfaceOAuthProviderProcessor<GoogleAccessTokenContext>- Parameters:
accessToken- access token used to initialize objectsocialApiObjectType- Type of object, which we wanted to return. Method will return null if this type is not supported by this processor- Returns:
- initialized object of required type or null if type wasn't found (supported) by this processor
-
obtainUserInfo
public com.google.api.services.oauth2.model.Userinfo obtainUserInfo(GoogleAccessTokenContext accessTokenContext) Description copied from interface:GoogleProcessorObtain informations about user from Google+ .- Specified by:
obtainUserInfoin interfaceGoogleProcessor- Parameters:
accessTokenContext- google access token- Returns:
- userinfo object with filled info about this user
-
getOAuth2Instance
public com.google.api.services.oauth2.Oauth2 getOAuth2Instance(GoogleAccessTokenContext accessTokenContext) Description copied from interface:GoogleProcessorObtain instance of GoogleOauth2object, which can be used to call various operations in Google API (obtain user informations, obtain informations about your access token etc)- Specified by:
getOAuth2Instancein interfaceGoogleProcessor- Returns:
- oauth2 object
-
getOAuth2InstanceImpl
protected com.google.api.services.oauth2.Oauth2 getOAuth2InstanceImpl(com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse tokenData) -
getPlusService
public com.google.api.services.plus.Plus getPlusService(GoogleAccessTokenContext accessTokenContext) Description copied from interface:GoogleProcessorObtain instance of Google (@link Plus} object, which can be used to call various operations in Google+ API (Obtain list of your friends, obtain your statuses, comments, activities etc...)- Specified by:
getPlusServicein interfaceGoogleProcessor- Returns:
- plus object
-
saveAccessTokenAttributesToUserProfile
public void saveAccessTokenAttributesToUserProfile(org.exoplatform.services.organization.UserProfile userProfile, OAuthCodec codec, GoogleAccessTokenContext accessToken) Description copied from interface:OAuthProviderProcessorSave accessToken data to given userProfile. Note that we are not calling any DB save operations, just filling data into given userProfile- Specified by:
saveAccessTokenAttributesToUserProfilein interfaceOAuthProviderProcessor<GoogleAccessTokenContext>- Parameters:
userProfile- where data about access token will be filledcodec- to encode some attributes (sensitive data) before save them to user profileaccessToken- specific access token for this OAuth processor
-
getAccessTokenFromUserProfile
public GoogleAccessTokenContext getAccessTokenFromUserProfile(org.exoplatform.services.organization.UserProfile userProfile, OAuthCodec codec) Description copied from interface:OAuthProviderProcessorObtain needed data from given userProfile and create accessToken from them- Specified by:
getAccessTokenFromUserProfilein interfaceOAuthProviderProcessor<GoogleAccessTokenContext>- Parameters:
userProfile- where data from access token will be obtainedcodec- to decode data from userProfile- Returns:
- accesstoken or null if accessToken is not found in persistent storage
-
removeAccessTokenFromUserProfile
public void removeAccessTokenFromUserProfile(org.exoplatform.services.organization.UserProfile userProfile) Description copied from interface:OAuthProviderProcessorRemove data about access token from this user profile- Specified by:
removeAccessTokenFromUserProfilein interfaceOAuthProviderProcessor<GoogleAccessTokenContext>- Parameters:
userProfile- from which data will be removed
-
revokeToken
Description copied from interface:OAuthProviderProcessorRevoke given access token on OAuth provider side, so application is removed from list of supported applications for given user- Specified by:
revokeTokenin interfaceOAuthProviderProcessor<GoogleAccessTokenContext>- Parameters:
accessTokenContext- access token to revoke- Throws:
OAuthException- with codeOAuthExceptionCode.TOKEN_REVOCATION_FAILEDif remote revocation of access token failed for some reason
-
refreshToken
Description copied from interface:GoogleProcessorRefresh Google+ token. Note that argument needs to have "refreshToken" available. The "accessToken" will be refreshed and updated directly on this instance of accessTokenContext- Specified by:
refreshTokenin interfaceGoogleProcessor
-