openid / AppAuth-Android

Android client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
https://openid.github.io/AppAuth-Android
Apache License 2.0
2.89k stars 891 forks source link

Authorization canceled error. #1034

Open oksuzozkan opened 11 months ago

oksuzozkan commented 11 months ago

Hi, i am trying to get access tokens from microsoft via appauth but i always get Authorization canceled error. use the example app from appAuth-Android and just changed the auth_config.json parameter.

The app open the webbrowers with this "https://businesscentral.dynamics.com/OAuthLanding.htm" link and close automaticly. onActivityResult resultCode always = RESULT_CANCELED

after clear chrome browsingdata: Not authorized error "Authorization Code exchange failed invalid_client".

i found something strange here: TokenActivitiy is opened after the web browser closes. There the exchangeAuthorizationCode function is called with the following parameters: authorizationResponse and do performTokenRequest the authorizationCode ist not null also can send Tokenrequest. Why not change the authstate? authorizationCode != null mean Authorization successfully or after get accesstoken is the state "isAuthorized= true"?

auth_config.json file "client_id": "myid", "redirect_uri": "https://businesscentral.dynamics.com/OAuthLanding.htm", "end_session_redirect_uri": "https://businesscentral.dynamics.com/OAuthLanding.htm", "authorization_scope": "https://api.businesscentral.dynamics.com/.default offline_access", "discovery_uri": "https://login.microsoftonline.com/mytenant/v2.0/.well-known/openid-configuration", "authorization_endpoint_uri": "https://login.microsoftonline.com/mytenant/oauth2/v2.0/authorize", "token_endpoint_uri": "https://login.microsoftonline.com/mytenant/oauth2/v2.0/token", "registration_endpoint_uri": "", "user_info_endpoint_uri": "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration", "https_required": true

Manifest file <activity android:name=".TokenActivity" android:exported="false"> <meta-data android:name="android.app.lib_name" android:value="" /> <activity android:name=".LoginActivity" android:exported="true"> <meta-data android:name="android.app.lib_name" android:value="" /> <activity android:name=".MainActivity" android:exported="true">

        <meta-data
            android:name="android.app.lib_name"
            android:value="" />
    </activity>

    <activity
        android:name="net.openid.appauth.RedirectUriReceiverActivity"
        tools:node="replace">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="https"
                android:host="businesscentral.dynamics.com"
                android:path="/OAuthLanding.htm"/>
        </intent-filter>
    </activity>
</application>

Logcat HostConnection::get() New Host Connection established 0xdd72a230, tid 11311 2024-01-04 12:45:11.136 11281-11311 HostConnection com.xxx.httpconnection D HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_sync_buffer_data GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 2024-01-04 12:45:11.137 11281-11311 ConfigStore com.xxx.httpconnection I android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0 2024-01-04 12:45:11.137 11281-11311 ConfigStore com.xxx.httpconnection I android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0 2024-01-04 12:45:11.137 11281-11311 OpenGLRenderer com.xxx.httpconnection I Initialized EGL, version 1.4 2024-01-04 12:45:11.137 11281-11311 OpenGLRenderer com.xxx.httpconnection D Swap behavior 1 2024-01-04 12:45:11.137 11281-11311 OpenGLRenderer com.xxx.httpconnection W Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 2024-01-04 12:45:11.137 11281-11311 OpenGLRenderer com.xxx.httpconnection D Swap behavior 0 2024-01-04 12:45:11.148 11281-11311 eglCodecCommon com.xxx.httpconnection D setVertexArrayObject: set vao to 0 (0) 0 0 2024-01-04 12:45:11.148 11281-11311 EGL_emulation com.xxx.httpconnection D eglCreateContext: 0xdd7053c0: maj 2 min 0 rcv 2 2024-01-04 12:45:11.152 11281-11311 EGL_emulation com.xxx.httpconnection D eglMakeCurrent: 0xdd7053c0: ver 2 0 (tinfo 0xdd703750) 2024-01-04 12:45:11.162 11281-11311 EGL_emulation com.xxx.httpconnection D eglMakeCurrent: 0xdd7053c0: ver 2 0 (tinfo 0xdd703750) 2024-01-04 12:45:16.754 11281-11281 ActivityThread com.xxx.httpconnection W handleWindowVisibility: no activity for token android.os.BinderProxy@3f1a52e

sollarp commented 9 months ago

I'm having a same issue any solution for this?

oksuzozkan commented 9 months ago

Hi, you cant try with customtabsService query in manifest file. it worked for me.

<queries>
        <intent>
            <action android:name="android.support.customtabs.action.CustomTabsService" />
        </intent>
    </queries>
oksuzozkan commented 7 months ago

I got the same error today, but slightly different. I have a new device, Zebra TC27 Android 13. Web browser opens after I click "Start Authorization" but does not close automatically. I clicked the x and closed the web browser myself, of course this action leads to "Authorization Canceled". After I have authorized myself once, tokenactivity should open the next time I run it, but authorization activity keeps coming up, and after I have entered email and password, web browser closes (on TC51 Android 8.1.0) but "Authorization Canceled" error comes up. Help Help Help :)

After logging in once, my Microsoft credentials are saved. I close the application (because authorization code exchange failed invalid_client) and open it again, try to authorize again, web browser opens, closes automatically but Loginactivity says AuthorizationException: {"type":0,"code":1,"errorDescription": "User aborted flow"} so Intent data is null