use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project urlaubsverwaltung by synyx.
the class GoogleCalendarSyncProviderServiceTest method getCalendarEventCount.
private Integer getCalendarEventCount() throws GeneralSecurityException, IOException {
NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setRefreshToken(REFRESH_TOKEN);
Credential credential = createCredentialWithRefreshToken(httpTransport, jsonFactory, tokenResponse);
Calendar calendar = new com.google.api.services.calendar.Calendar.Builder(httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build();
Calendar.Events.List events = calendar.events().list(CALENDAR_ID);
return events.execute().getItems().size();
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftStsOAuth2Strategy method getTokenResultFromHttpResponse.
@Override
@NonNull
protected TokenResult getTokenResultFromHttpResponse(@NonNull final HttpResponse response) throws ClientException {
final String methodName = ":getTokenResultFromHttpResponse";
Logger.verbose(TAG + methodName, "Getting TokenResult from HttpResponse...");
MicrosoftStsTokenResponse tokenResponse = null;
TokenErrorResponse tokenErrorResponse = null;
if (response.getStatusCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
// An error occurred
tokenErrorResponse = ObjectMapper.deserializeJsonStringToObject(response.getBody(), MicrosoftTokenErrorResponse.class);
tokenErrorResponse.setStatusCode(response.getStatusCode());
if (null != response.getHeaders()) {
tokenErrorResponse.setResponseHeadersJson(HeaderSerializationUtil.toJson(response.getHeaders()));
}
tokenErrorResponse.setResponseBody(response.getBody());
} else {
tokenResponse = ObjectMapper.deserializeJsonStringToObject(getBodyFromSuccessfulResponse(response.getBody()), MicrosoftStsTokenResponse.class);
}
final TokenResult result = new TokenResult(tokenResponse, tokenErrorResponse);
logResult(TAG, result);
if (null != response.getHeaders()) {
final Map<String, List<String>> responseHeaders = response.getHeaders();
final List<String> cliTelemValues;
if (null != (cliTelemValues = responseHeaders.get(X_MS_CLITELEM)) && !cliTelemValues.isEmpty()) {
// Element should only contain 1 value...
final String cliTelemHeader = cliTelemValues.get(0);
final CliTelemInfo cliTelemInfo = CliTelemInfo.fromXMsCliTelemHeader(cliTelemHeader);
// Parse and set the result...
result.setCliTelemInfo(cliTelemInfo);
if (null != tokenResponse && null != cliTelemInfo) {
tokenResponse.setSpeRing(cliTelemInfo.getSpeRing());
tokenResponse.setRefreshTokenAge(cliTelemInfo.getRefreshTokenAge());
tokenResponse.setCliTelemErrorCode(cliTelemInfo.getServerErrorCode());
tokenResponse.setCliTelemSubErrorCode(cliTelemInfo.getServerSubErrorCode());
}
}
}
return result;
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftStsOAuth2Strategy method createAccount.
@Override
public MicrosoftStsAccount createAccount(@NonNull final MicrosoftStsTokenResponse response) {
final String methodName = ":createAccount";
Logger.verbose(TAG + methodName, "Creating account from TokenResponse...");
IDToken idToken = null;
ClientInfo clientInfo = null;
try {
idToken = new IDToken(response.getIdToken());
clientInfo = new ClientInfo(response.getClientInfo());
} catch (ServiceException ccse) {
Logger.error(TAG + methodName, "Failed to construct IDToken or ClientInfo", null);
Logger.errorPII(TAG + methodName, "Failed with Exception", ccse);
throw new RuntimeException();
}
MicrosoftStsAccount account = new MicrosoftStsAccount(idToken, clientInfo);
account.setEnvironment(getIssuerCacheIdentifierFromTokenEndpoint());
return account;
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class MockTestStrategy method getTokenResult.
public TokenResult getTokenResult() {
final TokenResponse tokenResponse = MockTokenResponse.getMockSuccessTokenResponse();
final TokenResult tokenResult = new TokenResult(tokenResponse);
return tokenResult;
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class MockTestStrategy method performTokenRequest.
@Override
protected HttpResponse performTokenRequest(final MicrosoftStsTokenRequest tokenRequest) {
final TokenResult tokenResult = getTokenResult();
final TokenResponse tokenResponse = tokenResult.getTokenResponse();
final HttpResponse httpResponse = makeHttpResponseFromResponseObject(tokenResponse);
return httpResponse;
}
Aggregations