question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redirect is not fetched by Activity per intent - for all subsequent starts of an application. The first time it works.

See original GitHub issue

Configuration

  • Version: 0.8.1
  • Integration: Java on Android
  • Identity provider: our own

Description

Following the documentation I set up a small application doing the AuthGrant with our own IDP.

URI Receiver Activity configuration:

        <activity
            android:name="net.openid.appauth.RedirectUriReceiverActivity"
            tools:node="replace">
            <tools:validation testUrl="https://_host.domain.com_/oauth" />
            <intent-filter android:autoVerify="true">
                <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="_host.domain.com_"
                    android:path="/oauth"/>
            </intent-filter>
        </activity>

The java implementation is taken straight forward from the documentaion:

    protected void doit() {

        AuthorizationServiceConfiguration.fetchFromUrl(
                Uri.parse("https://_idp.somewhere.com_/.well-known/openid-configuration"),
                new AuthorizationServiceConfiguration.RetrieveConfigurationCallback() {
                    public void onFetchConfigurationCompleted(
                            @Nullable AuthorizationServiceConfiguration serviceConfiguration,
                            @Nullable AuthorizationException ex) {
                        if (ex != null) {
                            Log.e(TAG, "failed to fetch configuration",ex);
                            return;
                        }
                        else {
                            Log.i(TAG,"Obtaining AuthCode...");
                            obtainAuthCode(serviceConfiguration);
                        }
                        // use serviceConfiguration as needed
                    }
                });
    }

    protected void obtainAuthCode(AuthorizationServiceConfiguration serviceConfiguration) {
        AuthorizationRequest.Builder authRequestBuilder =
                new AuthorizationRequest.Builder(
                        serviceConfiguration, // the authorization service configuration
                        MY_CLIENT_ID, // the client ID, typically pre-registered and static
                        ResponseTypeValues.CODE, // the response_type value: we want a code
                        Uri.parse(MY_REDIRECT_URI)); // the redirect URI to which the auth response is sent

        AuthorizationRequest authRequest = authRequestBuilder
                .setScope("openid email profile")
                .setLoginHint("Password hint")
                .build();
        Log.i(TAG,"Starting AuthRequest...");
        doAuthorization(authRequest);
    }

    private void doAuthorization(AuthorizationRequest authRequest) {
        authService = new AuthorizationService(this);
        Intent authIntent = authService.getAuthorizationRequestIntent(authRequest);
        startActivityForResult(authIntent, RC_AUTH);
    }

    @SuppressLint("MissingSuperCall")
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == RC_AUTH) {

            AuthorizationResponse resp = AuthorizationResponse.fromIntent(data);
            AuthorizationException ex = AuthorizationException.fromIntent(data);

            if (resp != null) {
                Log.i(TAG,"Got AuthCode: "+resp.authorizationCode);
                // authorization completed
                Log.i(TAG,"Obtaining AccessToken...");
                obtainToken(resp);
            } else {
                // authorization failed, check ex for more details
            }
        } else {
            // ...
        }
    }

First time - after booting the emulator completly everything works fine. If I stop all tasks on the emulator and restart the application the app link is not consumed by the Activity but Chrome is presenting the AuthCode Redirect inside the browser. The Digital Asset Links is available per https and all tests state everything is ok. It’s also working the first time.

I only struggle with starting my app a 2nd or 3rd (…) time. The Redirect ist not fetched by my app. What might the issue here?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:23

github_iconTop GitHub Comments

1reaction
agologancommented, May 31, 2021

@huynguyennovem there are other options like asking the user to login every time via prompt:login but it really depends on your product’s expectations.

@sundeepkmallick been meaning to reply to your issue. Yes I do believe it stems from the same limitation.

1reaction
agologancommented, May 31, 2021

Per my current understanding: https://github.com/openid/AppAuth-Android/issues/679#issuecomment-824091995 chrome will launch an external app only on user interaction. In an SSO scenario my recommendation it to ask the user the select the account he’s currently logging in even if there is an active session. Having an intermediary page can also resolve the issue of the user wanting to switch accounts if he’s already logged into something else.

Read more comments on GitHub >

github_iconTop Results From Across the Web

App links intent filters in assetlinks.json not working on Android
First time I auto-formatted it with Ctrl + Alt + L, ... the 2nd intent filter and failed, and treated all our applinks...
Read more >
Sending the user to another app - Android Developers
Learn how to create an implicit intent for a particular action, and how to use it to start an activity that performs the...
Read more >
Android Threading: All You Need to Know - Toptal
When an application is launched in Android, it creates the first thread of ... Threads that are not attached to any activity/fragment: These...
Read more >
Detect and get rid of unwanted sneaky mobile redirects
Check your site on a mobile device or through emulation between each script/element removal, and see when the redirect stops. If you think...
Read more >
How To Handle Deep Linking in a React Native App
Let's start by creating a new React Native application. First, open up a ... The next step is to link all the libraries...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found