use of com.microsoft.appcenter.sasquatch.MSAAuthenticationProvider.TOKEN_URL in project mobile-center-sdk-android by Microsoft.
the class MSALoginActivity method getToken.
/**
* Get initial access token.
*/
private void getToken(final String code) {
Map<String, String> headers = new HashMap<>();
headers.put(DefaultHttpClient.CONTENT_TYPE_KEY, "application/x-www-form-urlencoded");
sHttpClient.callAsync(TOKEN_URL, DefaultHttpClient.METHOD_POST, headers, new HttpClient.CallTemplate() {
@Override
public String buildRequestBody() {
return REDIRECT_URI_PARAM + CLIENT_ID_PARAM + "&grant_type=authorization_code" + "&code=" + code;
}
@Override
public void onBeforeCalling(URL url, Map<String, String> headers) {
AppCenterLog.verbose(AppCenter.LOG_TAG, "Calling " + url + "...");
}
}, new ServiceCallback() {
@Override
public void onCallSucceeded(HttpResponse httpResponse) {
try {
JSONObject response = new JSONObject(httpResponse.getPayload());
String userId = response.getString(USER_ID);
mRefreshToken = response.getString(REFRESH_TOKEN);
mRefreshTokenScope = response.getString(SCOPE);
registerAppCenterAuthentication(userId);
} catch (JSONException e) {
onCallFailed(e);
}
}
@Override
public void onCallFailed(Exception e) {
handleCallFailure(e);
}
});
}
Aggregations