Class MicrosoftOAuth2TokenProvider
java.lang.Object
io.jmix.email.authentication.impl.AbstractOAuth2TokenProvider
io.jmix.email.authentication.impl.MicrosoftOAuth2TokenProvider
- All Implemented Interfaces:
OAuth2TokenProvider
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final RefreshTokenCapturingCacheAspectprotected com.microsoft.aad.msal4j.IAuthenticationResultprotected com.microsoft.aad.msal4j.AbstractClientApplicationBaseprotected OAuth2ClientTypeClient type the stored refresh token was issued to (seebuildClientApplication(OAuth2ClientType)).protected StringRefresh token value the provider considers to be currently persisted.protected static final longFields inherited from class io.jmix.email.authentication.impl.AbstractOAuth2TokenProvider
emailerProperties, refreshTokenManager -
Constructor Summary
ConstructorsConstructorDescriptionMicrosoftOAuth2TokenProvider(EmailerProperties emailerProperties, EmailRefreshTokenManager refreshTokenManager) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.microsoft.aad.msal4j.IAuthenticationResultacquireTokenByRefreshToken(String refreshToken) protected @Nullable com.microsoft.aad.msal4j.IAuthenticationResultTries to get a token from the MSAL cache, refreshing it silently if needed.protected Stringprotected com.microsoft.aad.msal4j.ConfidentialClientApplicationbuildClientApplication(com.microsoft.aad.msal4j.IClientCredential credential) protected com.microsoft.aad.msal4j.AbstractClientApplicationBasebuildClientApplication(OAuth2ClientType clientType) Entra binds a refresh token to the client type it was issued to (a token obtained by the device code flow is rejected when redeemed with a client secret - AADSTS700025), so the client application flavor must match the stored token.protected com.microsoft.aad.msal4j.PublicClientApplicationprotected com.microsoft.aad.msal4j.IClientCredential@NonNull StringGets access token by using refresh token.protected Stringprotected @Nullable Stringprotected Stringprotected booleanisExpiringSoon(com.microsoft.aad.msal4j.IAuthenticationResult result) protected voidMicrosoft rotates the refresh token on every redemption.Methods inherited from class io.jmix.email.authentication.impl.AbstractOAuth2TokenProvider
getClientId, getRefreshToken, getRequiredProperty, getSecret
-
Field Details
-
EXPIRATION_SKEW_MILLIS
protected static final long EXPIRATION_SKEW_MILLIS- See Also:
-
cacheAspect
-
clientApplication
protected com.microsoft.aad.msal4j.AbstractClientApplicationBase clientApplication -
cachedResult
protected com.microsoft.aad.msal4j.IAuthenticationResult cachedResult -
currentRefreshToken
Refresh token value the provider considers to be currently persisted. It is used to detect external token updates (via the email connection view or another application node) that require re-initialization of the client application. -
currentClientType
Client type the stored refresh token was issued to (seebuildClientApplication(OAuth2ClientType)).
-
-
Constructor Details
-
MicrosoftOAuth2TokenProvider
public MicrosoftOAuth2TokenProvider(EmailerProperties emailerProperties, EmailRefreshTokenManager refreshTokenManager)
-
-
Method Details
-
getAccessToken
Description copied from interface:OAuth2TokenProviderGets access token by using refresh token.- Returns:
- access token value
-
acquireTokenSilently
protected @Nullable com.microsoft.aad.msal4j.IAuthenticationResult acquireTokenSilently()Tries to get a token from the MSAL cache, refreshing it silently if needed. MSAL uses the latest rotated refresh token stored in its internal cache for silent refreshes.- Returns:
- authentication result or null if silent acquisition is not possible
-
acquireTokenByRefreshToken
protected com.microsoft.aad.msal4j.IAuthenticationResult acquireTokenByRefreshToken(String refreshToken) throws Exception - Throws:
Exception
-
isExpiringSoon
protected boolean isExpiringSoon(com.microsoft.aad.msal4j.IAuthenticationResult result) -
persistRotatedRefreshToken
protected void persistRotatedRefreshToken()Microsoft rotates the refresh token on every redemption. Stores the latest rotated value so that authentication survives application restarts after the originally configured token becomes invalid. -
getCapturedRefreshToken
-
createCredential
protected com.microsoft.aad.msal4j.IClientCredential createCredential() -
buildClientApplication
protected com.microsoft.aad.msal4j.AbstractClientApplicationBase buildClientApplication(OAuth2ClientType clientType) Entra binds a refresh token to the client type it was issued to (a token obtained by the device code flow is rejected when redeemed with a client secret - AADSTS700025), so the client application flavor must match the stored token. -
buildPublicClientApplication
protected com.microsoft.aad.msal4j.PublicClientApplication buildPublicClientApplication() -
buildClientApplication
protected com.microsoft.aad.msal4j.ConfidentialClientApplication buildClientApplication(com.microsoft.aad.msal4j.IClientCredential credential) -
getScopes
-
buildAuthorityUrl
-
getBaseAuthorityUrl
-
getTenant
-