Search in sources :

Example 1 with TOKEN_URL

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);
        }
    });
}
Also used : ServiceCallback(com.microsoft.appcenter.http.ServiceCallback) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) HttpUtils.createHttpClient(com.microsoft.appcenter.http.HttpUtils.createHttpClient) HttpClient(com.microsoft.appcenter.http.HttpClient) DefaultHttpClient(com.microsoft.appcenter.http.DefaultHttpClient) HttpResponse(com.microsoft.appcenter.http.HttpResponse) JSONException(org.json.JSONException) REDIRECT_URL(com.microsoft.appcenter.sasquatch.MSAAuthenticationProvider.REDIRECT_URL) URL(java.net.URL) AUTHORIZE_URL(com.microsoft.appcenter.sasquatch.MSAAuthenticationProvider.AUTHORIZE_URL) TOKEN_URL(com.microsoft.appcenter.sasquatch.MSAAuthenticationProvider.TOKEN_URL) SIGN_OUT_URL(com.microsoft.appcenter.sasquatch.MSAAuthenticationProvider.SIGN_OUT_URL) HttpException(com.microsoft.appcenter.http.HttpException) JSONException(org.json.JSONException)

Aggregations

DefaultHttpClient (com.microsoft.appcenter.http.DefaultHttpClient)1 HttpClient (com.microsoft.appcenter.http.HttpClient)1 HttpException (com.microsoft.appcenter.http.HttpException)1 HttpResponse (com.microsoft.appcenter.http.HttpResponse)1 HttpUtils.createHttpClient (com.microsoft.appcenter.http.HttpUtils.createHttpClient)1 ServiceCallback (com.microsoft.appcenter.http.ServiceCallback)1 AUTHORIZE_URL (com.microsoft.appcenter.sasquatch.MSAAuthenticationProvider.AUTHORIZE_URL)1 REDIRECT_URL (com.microsoft.appcenter.sasquatch.MSAAuthenticationProvider.REDIRECT_URL)1 SIGN_OUT_URL (com.microsoft.appcenter.sasquatch.MSAAuthenticationProvider.SIGN_OUT_URL)1 TOKEN_URL (com.microsoft.appcenter.sasquatch.MSAAuthenticationProvider.TOKEN_URL)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1