OAuth: application identifier or redirect_uri does not match authorization code

App Id or redirect_uri does not match authorization code.

Since I am completely a noob with OAuth and App development, I assume that the error (like most of the time) is on my side. My application has a (Login) button that directs the user to web browsing, where he logs into the Misfit API system through OAuth ( https://build.misfit.com/ ). As soon as he agrees to share his Misfit data with my application, the webview wants to redirect it to my redirect_uri, but I always get the above error message. Here is the code for OAuthActivity:

public class OAuthActivity extends Activity {

    public static String OAUTH_URL = "https://api.misfitwearables.com/auth/dialog/authorize";
    public static String OAUTH_ACCESS_TOKEN_URL = "https://api.misfitwearables.com/auth/tokens/exchange";

    public static String CLIENT_ID = "ID";
    public static String CLIENT_SECRET = "Secret";
    public static String CALLBACK_URL = "http://iss.uni-saarland.de/";
    public static String SCOPE = "public,birthday,email,tracking,session,sleeps";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auth_o);

        String url = OAUTH_URL + "?response_type=code" +"&client_id=" + CLIENT_ID + "&redirect_uri=" + CALLBACK_URL + "&scope=" + SCOPE;

        WebView webview = (WebView)findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);
        final SharedPreferences prefs = this.getSharedPreferences(
                "com.iss_fitness.myapplication", Context.MODE_PRIVATE);
        webview.setWebViewClient(new WebViewClient() {
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                String accessTokenFragment = "access_token=";
                String accessCodeFragment = "code=";

                // We hijack the GET request to extract the OAuth parameters

                if (url.contains(accessTokenFragment)) {
                    // the GET request contains directly the token
                    String accessToken = url.substring(url.indexOf(accessTokenFragment));
                    prefs.edit().putString("Token", accessToken);

                } else if(url.contains(accessCodeFragment)) {
                    // the GET request contains an authorization code
                    String accessCode = url.substring(url.indexOf(accessCodeFragment));
                    prefs.edit().putString("Code", accessCode);

                    String query = "grant_type=authorization_code" + "&client_id=" + CLIENT_ID + "&client_secret=" + CLIENT_SECRET + "&code=" + accessCode + "&redirect_uri=" + CALLBACK_URL;
                    view.postUrl(OAUTH_ACCESS_TOKEN_URL, query.getBytes());
                }
            }



        });
        webview.loadUrl(url);


    }
}

, - URL , , , . , redirect_uri, , .

: - URI Misfit - URI , . - Intent , , URI .

==========================================

→ → →

POST: https://api.misfitwearables.com/auth/tokens/exchange

:

{
    "grant_type":"authorization_code",
    "code":{{USER CODE FROM AUTH}},
    "redirect_uri":"SAME REDIRECT_URI AS IN AUTH",
    "client_id":{{my app id}},
    "client_secret":{{my app secret}}

}

:

{
  "error": "invalid_grant",
  "error_description": "App Id or redirect_uri does not match authorization code"
}
+4
1

, , Google, google api.

URL- , :

  • .
  • .
  • , URL-

enter image description here

, .

0

All Articles