alexziskind1 / nativescript-oauth2

Other
86 stars 93 forks source link

SFSafariController is not returning back to app after Authenticating with Azure AD #136

Open KitGardner opened 4 years ago

KitGardner commented 4 years ago

Hi there. I am developing a customer Portal App for IOS and Android. At the moment we are focusing on IOS. We use Active Directory as our Identity provider so I am using the microsoft provider to interface with it. As they are OpenID compliant this causes the plugin to go the route of using the SFSafariController instead of a web view. There are two issues I have been running into.

The first one is that the first time I kick off the login it fails, I get a message about the SFSafariController was not found during runtime and it is now being initialized. I suspect this is something that I just need to wrap an error handler around or try to initialize early in the app life.

The second issue is that when the SFSafariController is loaded, I am able to sign in successfully, but then the controller just sits there loading eternally and I am not getting my access token from the call.

I tried commenting out the code that decides to use the SafariController if the provider is OpenId-Full so that it has to use a web view and this is working. The user can sign in and we get a token.

I would prefer to use the SFSafariController since it is more secure but as mentioned already it gets stuck. I know that my app is setup correctly for the redirect because I can enter the custom URL in my devices' browser and it opens my app. Additionally, I played with another plugin to override the UIApplicationDelegate and with this I was able to grab the Authorization Code from the Safari Controller. I can use this and do the rest of the auth flow myself, but I currently don't have a solution to close the browser. So that is not a big sticking point, but I would prefer a smoother experience.

My final thoughts is that I suspect the issue lies somewhere in the ios application delegate that is created when it goes down the path of using the SFSafariController.

One final thing I want to add, is that we have users from two different Active Directories, so I cannot initialize the provider when the app opens. I first need the user to enter an email for the first time, and then the app remembers what domain they are in from then on.

Due to this, I do have to change the authority and tokenEndpointBase properties of the microsoft provider to use our custom tenant Id instead of common.

Which platform(s) does your issue occur on?

So far it is just IOS. I have not tested on Android

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

"dependencies": { "@angular/animations": "~8.2.0", "@angular/common": "~8.2.0", "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", "@angular/forms": "~8.2.0", "@angular/platform-browser": "~8.2.0", "@angular/platform-browser-dynamic": "~8.2.0", "@angular/router": "~8.2.0", "@nativescript/theme": "~2.3.3", "karma": "*", "karma-jasmine": "3.1.1", "karma-nativescript-launcher": "0.4.0", "karma-webpack": "3.0.5", "nativescript-angular": "~8.21.0", "nativescript-oauth2": "^2.4.4", "nativescript-plugin-firebase": "^10.5.2", "nativescript-ui-calendar": "^6.1.0", "nativescript-unit-test-runner": "^0.7.0", "reflect-metadata": "~0.1.12", "rxjs": "^6.4.0", "tns-core-modules": "~6.5.0", "tns-platform-declarations": "^6.5.15", "zone.js": "~0.9.1" }, "devDependencies": { "@angular/compiler-cli": "~8.2.0", "@ngtools/webpack": "~8.2.0", "@types/jasmine": "^3.5.9", "nativescript-dev-webpack": "~1.5.1", "typescript": "~3.5.3" }

email-nkishor commented 3 years ago

Hi @NathanWalker @alexziskind1

I am facing same issue on IOS and android build working fine. still working on it and waiting for solutions.

keithgulbro commented 3 years ago

Ran into the same issue. In my case, updating my project to Nativescript 7 and removing any rogue files that weren't needed did the trick.

Thisgio commented 3 years ago

@KitGardner Still no fix?