NAzT
8/30/2016 - 6:33 AM

NETPIE-OAUTH.java

NETPIE-OAUTH.java

private void fetchAndCacheMicroGearTokens(final String appId, final String appKey,
                                          final String appSecret,
                                          final NetpieAuthModule.NetpieAuthCallback authCallback) {
    String authorizationCallback = "scope=&appid=" + appId + "&mgrev=NJS1a&verifier=NJS1a";
    // STEP 1: GET OAuth Authorization
    mAuthorization = mOAuthRequest.OAuth(appKey, appSecret, authorizationCallback);
    // STEP 2: GET RequestToken
    sendPostRequestToNetpie("http://ga.netpie.io:8080/api/rtoken",
            mAuthorization, new RequestNetpieCallback() {
                @Override
                public void onFinished(String result, String token) {
                    // result = "yes"
                    if (!token.isEmpty()) {
                        // STEP 3: parse RequestToken
                        OAuthRequestToken _oAuthRequestToken = parseOAuthRequestTokenString(token);
                        // STEP 4: GET AccessToken
                        mOAuthAccessToken = getOAuthSecretToken(appKey,
                                appSecret, _oAuthRequestToken);
                        // STEP 5: Serialize OAuth AccessToken To file.
                        saveAllOAuthToken(mOAuthAccessToken, appKey);
                    }
                    authCallback.onFinished(result);
                }
            });
}