invalid_grant пытается получить токен oAuth2 - PullRequest
0 голосов
/ 26 октября 2018

Привет всем, я пытаюсь получить токен доступа Oauth2 из API nop-template для nopCommerce в Android, но столкнулся с этой ошибкой при вызове oAuthClient.accessToken:

OAuthProblemException {description = 'null', error = 'invalid_grant', uri = 'null', state = 'null', scope = 'null'}

мой код:

import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;

import net.smartam.leeloo.client.OAuthClient;
import net.smartam.leeloo.client.URLConnectionClient;
import net.smartam.leeloo.client.request.OAuthClientRequest;
import net.smartam.leeloo.client.response.OAuthAccessTokenResponse;
import net.smartam.leeloo.common.exception.OAuthProblemException;
import net.smartam.leeloo.common.exception.OAuthSystemException;
import net.smartam.leeloo.common.message.types.GrantType;

import java.util.UUID;

class accessToken extends AsyncTask<Uri, Void, Void> {


    @Override
    protected Void doInBackground(Uri... uri) {

        if (uri[0] != null && uri[0].toString()
                .startsWith("myapp://Oauthresponse")) {

            String code = UUID.randomUUID().toString();

            OAuthClientRequest request = null;

            try {
                request = OAuthClientRequest.tokenLocation("http://www.myStore.com/api/token")
                        .setGrantType(GrantType.AUTHORIZATION_CODE)
                        .setClientId("ClientId")
                        .setClientSecret("ClientSecret")
                        .setRedirectURI("myapp://Oauthresponse")
                        .setCode(code)
                        .buildBodyMessage();

            } catch (OAuthSystemException e) {
                e.printStackTrace();
            }

            OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

            OAuthAccessTokenResponse response = null;

          try {
              response = oAuthClient.accessToken(request);
            } catch (OAuthSystemException e) {
                e.printStackTrace();
                Log.d("khata", e.toString());
            } catch (OAuthProblemException e) {
                e.printStackTrace();
                Log.d("khata", e.toString());
            }
            String token = response.getAccessToken();
        }

        return null;
    }
}

Может кто-нибудь помочь?

...