Class MicrosoftOAuth2TokenProvider

java.lang.Object
io.jmix.email.authentication.impl.AbstractOAuth2TokenProvider
io.jmix.email.authentication.impl.MicrosoftOAuth2TokenProvider
All Implemented Interfaces:
OAuth2TokenProvider

public class MicrosoftOAuth2TokenProvider extends AbstractOAuth2TokenProvider
  • Field Details

    • EXPIRATION_SKEW_MILLIS

      protected static final long EXPIRATION_SKEW_MILLIS
      See Also:
    • cacheAspect

      protected final RefreshTokenCapturingCacheAspect cacheAspect
    • clientApplication

      protected com.microsoft.aad.msal4j.AbstractClientApplicationBase clientApplication
    • cachedResult

      protected com.microsoft.aad.msal4j.IAuthenticationResult cachedResult
    • currentRefreshToken

      protected String 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

      protected OAuth2ClientType currentClientType
      Client type the stored refresh token was issued to (see buildClientApplication(OAuth2ClientType)).
  • Constructor Details

  • Method Details

    • getAccessToken

      public @NonNull String getAccessToken()
      Description copied from interface: OAuth2TokenProvider
      Gets 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

      protected @Nullable String 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

      protected Set<String> getScopes()
    • buildAuthorityUrl

      protected String buildAuthorityUrl()
    • getBaseAuthorityUrl

      protected String getBaseAuthorityUrl()
    • getTenant

      protected String getTenant()