Class MicrosoftOAuth2AuthorizationCodeFlow
java.lang.Object
io.jmix.email.authentication.impl.AbstractOAuth2Flow
io.jmix.email.authentication.impl.MicrosoftOAuth2AuthorizationCodeFlow
- All Implemented Interfaces:
OAuth2AuthorizationCodeFlow
@NullMarked
public class MicrosoftOAuth2AuthorizationCodeFlow
extends AbstractOAuth2Flow
implements OAuth2AuthorizationCodeFlow
Authorization code flow for Microsoft accounts. MSAL appends the reserved scopes
(
offline_access etc.) required to obtain a refresh token.-
Field Summary
Fields inherited from class io.jmix.email.authentication.impl.AbstractOAuth2Flow
emailerProperties, refreshTokenManager -
Constructor Summary
ConstructorsConstructorDescriptionMicrosoftOAuth2AuthorizationCodeFlow(EmailerProperties emailerProperties, EmailRefreshTokenManager refreshTokenManager) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.microsoft.aad.msal4j.IAuthenticationResultacquireTokenByAuthorizationCode(RefreshTokenCapturingCacheAspect cacheAspect, String authorizationCode, String redirectUri) protected StringbuildAuthorizationUrl(String redirectUri, String state) The URL is built manually: the authorization response must come back as a GET redirect so that the callback view can read the query parameters (a POST is also rejected by the CSRF protection), but MSAL silently overridesResponseMode.QUERYwithform_post.protected com.microsoft.aad.msal4j.ConfidentialClientApplicationbuildClientApplication(@Nullable RefreshTokenCapturingCacheAspect cacheAspect) voidcompleteAuthorization(String authorizationCode, String redirectUri) Exchanges the authorization code received on the callback for tokens and stores the obtained refresh token viaEmailRefreshTokenManager.Scopes requested on the consent page.protected Stringprotected @Nullable StringgetCapturedRefreshToken(RefreshTokenCapturingCacheAspect cacheAspect) protected StringMethods inherited from class io.jmix.email.authentication.impl.AbstractOAuth2Flow
encodeForm, getClientId, getRequiredProperty, getSecret
-
Constructor Details
-
MicrosoftOAuth2AuthorizationCodeFlow
public MicrosoftOAuth2AuthorizationCodeFlow(EmailerProperties emailerProperties, EmailRefreshTokenManager refreshTokenManager)
-
-
Method Details
-
buildAuthorizationUrl
The URL is built manually: the authorization response must come back as a GET redirect so that the callback view can read the query parameters (a POST is also rejected by the CSRF protection), but MSAL silently overridesResponseMode.QUERYwithform_post. The Entra endpoint itself supportsresponse_mode=queryas defined by the OAuth spec.- Specified by:
buildAuthorizationUrlin interfaceOAuth2AuthorizationCodeFlow- Parameters:
redirectUri- application callback URI registered for the OAuth clientstate- opaque value used to protect the round trip against CSRF- Returns:
- URL to redirect the user to
-
getAuthorizationScopes
Scopes requested on the consent page. Unlike MSAL-built requests, the manually built URL must include the reserved scopes (offline_accessis required to receive a refresh token) explicitly. -
completeAuthorization
Description copied from interface:OAuth2AuthorizationCodeFlowExchanges the authorization code received on the callback for tokens and stores the obtained refresh token viaEmailRefreshTokenManager.- Specified by:
completeAuthorizationin interfaceOAuth2AuthorizationCodeFlow- Parameters:
authorizationCode- code received on the redirect URIredirectUri- the same redirect URI that was used to build the authorization URL
-
acquireTokenByAuthorizationCode
protected com.microsoft.aad.msal4j.IAuthenticationResult acquireTokenByAuthorizationCode(RefreshTokenCapturingCacheAspect cacheAspect, String authorizationCode, String redirectUri) throws Exception - Throws:
Exception
-
getCapturedRefreshToken
-
buildClientApplication
protected com.microsoft.aad.msal4j.ConfidentialClientApplication buildClientApplication(@Nullable RefreshTokenCapturingCacheAspect cacheAspect) -
getScopes
-
buildAuthorityUrl
-
getBaseAuthorityUrl
-
getTenant
-