Search in sources :

Example 21 with ServiceException

use of com.microsoft.identity.common.exception.ServiceException in project microsoft-authentication-library-common-for-android by AzureAD.

the class MicrosoftStsAccountCredentialAdapter method createRefreshToken.

@Override
public RefreshTokenRecord createRefreshToken(final MicrosoftStsOAuth2Strategy strategy, final MicrosoftStsAuthorizationRequest request, final MicrosoftStsTokenResponse response) {
    try {
        final long cachedAt = getCachedAt();
        final ClientInfo clientInfo = new ClientInfo(response.getClientInfo());
        final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
        // Required
        refreshToken.setCredentialType(CredentialType.RefreshToken.name());
        refreshToken.setEnvironment(strategy.getIssuerCacheIdentifierFromTokenEndpoint());
        refreshToken.setHomeAccountId(SchemaUtil.getHomeAccountId(clientInfo));
        refreshToken.setClientId(request.getClientId());
        refreshToken.setSecret(response.getRefreshToken());
        // Optional
        refreshToken.setFamilyId(response.getFamilyId());
        refreshToken.setTarget(getTarget(request.getScope(), response.getScope()));
        // TODO are these needed? Expected?
        // generated @ client side
        refreshToken.setCachedAt(String.valueOf(cachedAt));
        return refreshToken;
    } catch (ServiceException e) {
        // TODO handle this properly
        throw new RuntimeException(e);
    }
}
Also used : ServiceException(com.microsoft.identity.common.exception.ServiceException) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) ClientInfo(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.ClientInfo)

Example 22 with ServiceException

use of com.microsoft.identity.common.exception.ServiceException in project microsoft-authentication-library-common-for-android by AzureAD.

the class MicrosoftStsAccountCredentialAdapter method createIdToken.

@Override
public IdTokenRecord createIdToken(final MicrosoftStsOAuth2Strategy strategy, final MicrosoftStsAuthorizationRequest request, final MicrosoftStsTokenResponse response) {
    try {
        final ClientInfo clientInfo = new ClientInfo(response.getClientInfo());
        final IdTokenRecord idToken = new IdTokenRecord();
        // Required fields
        idToken.setHomeAccountId(SchemaUtil.getHomeAccountId(clientInfo));
        idToken.setEnvironment(strategy.getIssuerCacheIdentifierFromTokenEndpoint());
        idToken.setRealm(getRealm(strategy, response));
        idToken.setCredentialType(SchemaUtil.getCredentialTypeFromVersion(response.getIdToken()));
        idToken.setClientId(request.getClientId());
        idToken.setSecret(response.getIdToken());
        idToken.setAuthority(strategy.getAuthorityFromTokenEndpoint());
        return idToken;
    } catch (ServiceException e) {
        // TODO handle this properly
        throw new RuntimeException(e);
    }
}
Also used : IdTokenRecord(com.microsoft.identity.common.internal.dto.IdTokenRecord) ServiceException(com.microsoft.identity.common.exception.ServiceException) ClientInfo(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.ClientInfo)

Example 23 with ServiceException

use of com.microsoft.identity.common.exception.ServiceException in project microsoft-authentication-library-common-for-android by AzureAD.

the class MicrosoftStsAccountCredentialAdapter method createAccessToken.

@Override
public AccessTokenRecord createAccessToken(final MicrosoftStsOAuth2Strategy strategy, final MicrosoftStsAuthorizationRequest request, final MicrosoftStsTokenResponse response) {
    try {
        final long cachedAt = getCachedAt();
        final long expiresOn = getExpiresOn(response);
        final ClientInfo clientInfo = new ClientInfo(response.getClientInfo());
        final AccessTokenRecord accessToken = new AccessTokenRecord();
        // Required fields
        accessToken.setCredentialType(getCredentialType(response.getTokenType()));
        accessToken.setHomeAccountId(SchemaUtil.getHomeAccountId(clientInfo));
        accessToken.setRealm(getRealm(strategy, response));
        accessToken.setEnvironment(strategy.getIssuerCacheIdentifierFromTokenEndpoint());
        accessToken.setClientId(request.getClientId());
        accessToken.setTarget(getTarget(request.getScope(), response.getScope()));
        // generated @ client side
        accessToken.setCachedAt(String.valueOf(cachedAt));
        accessToken.setExpiresOn(String.valueOf(expiresOn));
        accessToken.setSecret(response.getAccessToken());
        // Optional fields
        accessToken.setExtendedExpiresOn(getExtendedExpiresOn(response));
        accessToken.setAuthority(strategy.getAuthorityFromTokenEndpoint());
        accessToken.setAccessTokenType(response.getTokenType());
        // Use case insensitive match - ESTS will not capitalize scheme...
        if (SCHEME_POP.equalsIgnoreCase(response.getTokenType())) {
            accessToken.setKid(strategy.getDeviceAtPopThumbprint());
        }
        return accessToken;
    } catch (ServiceException e) {
        // TODO handle this properly
        throw new RuntimeException(e);
    }
}
Also used : ServiceException(com.microsoft.identity.common.exception.ServiceException) ClientInfo(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.ClientInfo) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord)

Aggregations

ServiceException (com.microsoft.identity.common.exception.ServiceException)23 ClientInfo (com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.ClientInfo)8 IDToken (com.microsoft.identity.common.internal.providers.oauth2.IDToken)7 ClientException (com.microsoft.identity.common.exception.ClientException)4 Nullable (androidx.annotation.Nullable)3 IOException (java.io.IOException)3 URL (java.net.URL)3 NonNull (androidx.annotation.NonNull)2 ArgumentException (com.microsoft.identity.common.exception.ArgumentException)2 BaseException (com.microsoft.identity.common.exception.BaseException)2 BrokerResult (com.microsoft.identity.common.internal.broker.BrokerResult)2 AuthorizationResult (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)2 OAuth2Strategy (com.microsoft.identity.common.internal.providers.oauth2.OAuth2Strategy)2 OAuth2StrategyParameters (com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters)2 ApiEndEvent (com.microsoft.identity.common.internal.telemetry.events.ApiEndEvent)2 ApiStartEvent (com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent)2 JSONException (org.json.JSONException)2 Bundle (android.os.Bundle)1 JsonObject (com.google.gson.JsonObject)1 JWSBuilder (com.microsoft.identity.common.adal.internal.JWSBuilder)1