azure-activedirectory-library-for-cordova icon indicating copy to clipboard operation
azure-activedirectory-library-for-cordova copied to clipboard

Back to my Android App. Ionic 4. Need help please.

Open klochko7 opened this issue 5 years ago • 8 comments

Hi all ! Could anyone suggest please, how to implement a redirect back to my Android App after authentication ? I try to use such code, but nothing happened after I correctly entered email and password on Microsoft authentication page. Microsoft show authentication page to me again.


    let authContext: AuthenticationContext = this.msAdal.createAuthenticationContext('https://login.windows.net/common');

    authContext.acquireTokenAsync('https://graph.windows.net', 'ClinetID', 'http://localhost:8000','','')
        .then((authResponse: AuthenticationResult) => {
          console.log('Token is' , authResponse.accessToken);
          console.log('Token will expire on', authResponse.expiresOn);
        })
        .catch((e: any) => console.log('Authentication failed', e));

klochko7 avatar Oct 22 '19 14:10 klochko7

@klochko7 This library isn't supported anymore. You could try to use a forked version that has been patched to support some of the native adal api updates. If you go down that route, you could enable broker based authentication option.

leewhitbeck avatar Oct 22 '19 17:10 leewhitbeck

leewhitbeck, good day! You mean, that I can not integrate this library with Ionic 4 framework? It dose not work?

Where I can find forked version?

What do you mean about?

If you go down that route, you could enable broker based authentication option.

klochko7 avatar Oct 23 '19 09:10 klochko7

@klochko7 This library will not work for you as is. The underlying IOS and Android adal libraries have changed, and this library does not support those new changes.

We are using this forked repo, which was updated to support the latest IOS/Android adal changes. I can't guarantee it will work for your use cases, but it is working for our Ionic4 application.

We use Microsoft Authenticator and use broker based authentication. To enable that option you simply need to set that configuration option to true like so:Microsoft.ADAL.AuthenticationSettings.setUseBroker(true);

See Broker Support here to learn more about broker based auth

leewhitbeck avatar Oct 23 '19 14:10 leewhitbeck

leewhitbeck,thank you very much. Could suggest please.. when the user is authenticated successfully I want to redirect it to the app root page. What will be the redirectUrl for authContext.acquireTokenAsync?

klochko7 avatar Oct 24 '19 13:10 klochko7

See the broker support section. You will need to register your url in azure and then ensure it is in this format for IOS (see docs for Android) : x-msauth-<your-bundle-id>://<your.bundle.id>.

You should see a valid token after the auth flow resolved in the acquireTokenAsync then clause: .then((authResponse)=> { ..get token }

In terms of redirecting back to appRoot, i'm not sure why you are doing that. I'd suggest using an AuthGuard.

leewhitbeck avatar Oct 24 '19 16:10 leewhitbeck

@klochko7 Another option is to use Ionic's new Auth Connect.. This would work with Ionic4 too.

leewhitbeck avatar Oct 24 '19 16:10 leewhitbeck

leewhitbeck, thank you very much for your answer.

klochko7 avatar Oct 25 '19 15:10 klochko7

@leewhitbeck Can you please share the implementation steps for ionic-4 ?? That would be a great help

LalitKushwah avatar Nov 16 '19 21:11 LalitKushwah