generic-oauth2 icon indicating copy to clipboard operation
generic-oauth2 copied to clipboard

Ionic Angular capacitor-oauth2 plugin build guard

Open sallyg1 opened this issue 3 years ago • 6 comments

Hi ,

I am building mobile app in Ionic angular, I am using Azure AD B2C as my identity provider. I am able to login and authenticate using the plugin @byteowls/capacitor-oauth2

My question is how do I build auth guard in angular to protect internal pages ? is there a method provided by the capacitor-oauth2 plugin to check if user is authenticated or logged in ?

Any help is appreciated

sallyg1 avatar Jul 29 '22 16:07 sallyg1

can you paste the sample here, 'Azure authenticate' I can successfully authenticate in browser, meanwhile in android popup is showing while clicking continue I got warning as ' Navigation is unreachable: msauth://com.XXXXX.XXXXX/XXXXXXXXXXXXX?code=XXXXXXXXXXXXXX&session_state=XXXXXXXXXXXXX '

ananthakrish98 avatar Sep 09 '22 08:09 ananthakrish98

I used this github sample to make the authentication work https://github.com/loonix/capacitor-oauth2-azure-example

sallyg1 avatar Sep 09 '22 21:09 sallyg1

I used this github sample to make the authentication work https://github.com/loonix/capacitor-oauth2-azure-example

I tried the same ,except config the config i used

oauth2Options = { appId: 'XXXXXXXXXXXXXXXXX', authorizationBaseUrl: 'https://login.microsoftonline.com/xxxxxxxx/oauth2/v2.0/authorize', accessTokenEndpoint: 'https://login.microsoftonline.com/xxxxxxxx/oauth2/v2.0/token', scope: 'https://graph.microsoft.com/User.Read', resourceUrl: "https://graph.microsoft.com/v1.0/me/", pkceEnabled: true, logsEnabled: true, responseType: 'code',

web: {

  redirectUrl: 'http://localhost:8100/login',
  windowOptions: "height=600,left=0,top=0",
},
android: {


  redirectUrl: 'msauth://com.sxxx.xxxxxsb/xxxZydORfyjxxxx',

 
},
ios: {
  pkceEnabled: true,
  responseType: 'code',
  redirectUrl: 'msauth://com.sxxx.xxxxxsb/xxxZydORfyjxxxx',
  accessTokenEndpoint: 'https://login.microsoftonline.com/xxxxxxxx/oauth2/v2.0/token',
}

}; I am getting the same error navigation is unreachable screenshot

ananthakrish98 avatar Sep 10 '22 09:09 ananthakrish98

you web scope doesn't look right. It should not be Microsoft graph. It should be the url you find in the "Expose an API", the application ID URI and also the same URI is listed in your API permission list and you have given admin consent

sallyg1 avatar Sep 12 '22 20:09 sallyg1

you web scope doesn't look right. It should not be Microsoft graph. It should be the url you find in the "Expose an API", the application ID URI and also the same URI is listed in your API permission list and you have given admin consent

Web authentication is working fine, the above mention error coming in android authentication, the screen shot shown is while debugging via chrome inspect

ananthakrish98 avatar Sep 13 '22 12:09 ananthakrish98

you web scope doesn't look right. It should not be Microsoft graph. It should be the url you find in the "Expose an API", the application ID URI and also the same URI is listed in your API permission list and you have given admin consent

Web authentication is working fine, the above mention error coming in android authentication, the screen shot shown is while debugging via chrome inspect

do you have any updates? I am facing same issue.

di-appteam avatar May 01 '23 12:05 di-appteam