proyecto26 / react-native-inappbrowser

📱InAppBrowser for React Native (Android & iOS) 🤘
https://www.npmjs.com/package/react-native-inappbrowser-reborn
MIT License
1.29k stars 220 forks source link

InAppBrowser.openAuth method not working correctly. #380

Closed anujraghuvanshi closed 1 year ago

anujraghuvanshi commented 1 year ago

I am using InAppBrowser.openAuth method to login with Microsoft AD & it's not working as expected. The Issues are -

  1. Login
    • When logged in, getting {type: "success", url: "My App Redirect URI"} with - So it's not including any other things like scopes, refresh token, accessToken etc.
    • When doing cancel, It only returns {type: "cancel"}.
  2. Logout
    • It gives only {type: "cancel"} when we close the Logout window either we close after successful logout or without logout.

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

What I expect here is -

Is there any code involved?

InAppBrowser.openAuth() is what I am using currently and opening this url for authorisation with my credentials.

For logout, authorize just needs to be changed to logout in URL.

Any quick work around or fix will be appreciable.

jdnichollsc commented 1 year ago

Hello Anuj, hope you're doing well Please use a BackEnd for that, you can include these parameters and redirect your users to the app again having this logic from Server Side (cloud function, ExpressJS, etc)

anujraghuvanshi commented 1 year ago

Okay, Let's say I do Login with the backend. then somehow Can I get the correct response while Logout itself? If only IAB is closed then it should throw type cancel. When the logout is successful and tries to close, Then I expect to give a correct result that the user was logged out or a different type. Thanks!

jdnichollsc commented 1 year ago

Hello dude, please attach a repository (app & backend) to be able to help you to reproduce your issue and then I can help you to fix that flow 👍

anujraghuvanshi commented 1 year ago

Actually, till the process of login, I am using only frontend, And opening this link - https://login.microsoftonline.com/%7Btenant-id%7D/oauth2/v2.0/authorize?scope=offline_access%20openid%20profile%20email%20user.read&clientId=%7Bclient-id%7D&response_type=code%20id_token&response_mode=fragment&state=%7Bstate%7D&nonce=%7Bnonce%7D&code_challenge_method=plain&code_challenge=%7Bcode_challenge%7D&redirect_uri=%7Bredirect-url%7D

For logout, just need to replace authorize -> logout. I was using this package for login but this doesn't work for logout. Getting the same issue as I have mentioned above. Either Logout is successful or not, it gives the user canceled callback.

Let me know if you need any more details... Thanks!

anujraghuvanshi commented 1 year ago

For more information, I am adding a few more things here - As described above, I wanted to make Complete Microsoft Azure AD Authentication flow using this plugin as other plugins not working as intended.

I have called this for doing login with MICROSOFT_LOGIN_URL which includes additional parameters like scopes in the URL

InAppBrowser.openAuth(MICROSOFT_LOGIN_URL, DEEP_LINK_FOR_APP, {
  ephemeralWebSession: false,
  showTitle: false,
  enableUrlBarHiding: true,
  enableDefaultShare: false
});

Now this plugin is also using web view and returning me scopes which I pass as params to get. But using this plugin, I get only Type & Code when I log in. I need those things also which should include refreshToken, accessToken also


Second thing, I am again calling the above method with the logout URL, Now A WebPage opens as a modal, Either I cancel it after selecting an account to log out & logging out or without doing logout. It returns only type: cancel.

So is this possible what I am trying to achieve and if Yes, Then do I need to do it in some different way? Thanks!

jdnichollsc commented 1 year ago

Hello mate, sorry for the delay

In both cases (login, logout) you need to use the openAuth method, but also you need a BackEnd (NodeJS, etc) for handling these http redirects with external providers, and then depending on the platform redirect users to the app using deep linking (your backend works like a middleware here to include params via url).

BTW, we're not using WebView, more details here