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);
}
}
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);
}
}
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);
}
}
Aggregations