alexziskind1 / nativescript-oauth2

Other
86 stars 93 forks source link

iOS is not sign in due to URL scheme #156

Open eduardocalixtokorp opened 3 years ago

eduardocalixtokorp commented 3 years ago

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.

Only Sign in using iOS After the login process is finished, the oauth server returns to <REDIRECT>://auth, but nativescript-oauth2 doesn't recognize the returned value. This way app keeps in the login page (from oauth server).

PS: completion never calls it back, but IOS app selection pop-up is showed. PS 2: I was able to identify the problem using nativescript-urlhandler package, with the same config it was able to return the returned url, containing all needed query params such as code image

Is there any code involved?

loginWithCompletion call

this.oauthClient.loginWithCompletion((tokenResult: ITnsOAuthTokenResult, error: Error | string) => {
    console.log('this line is not called when error is returned from oauth server');
}

Info.plist

<key>CFBundleURLTypes</key>
<array>
  <dict>
      <key>CFBundleTypeRole</key>
      <string>Editor</string>
      <key>CFBundleURLName</key>
      <string>com.organization.myapp</string>
      <key>CFBundleURLSchemes</key>
      <array>
          <string>com.myapp.app</string>
          <string>com.myapp.app.localhost</string>
      </array>
  </dict>
</array>
Thisgio commented 3 years ago

Still no fix? @eduardocalixtokorp

eduardocalixtokorp commented 3 years ago

I'll check it soon in 3.0.6 version (currently using 3.0.5). I was able to make it work by doing a workaround, which uses nativescript-urlhandler package and manually calls resumeWithUrl method.

KarthikMalaimegam commented 3 years ago

I am also facing the same issue. plugin overriding the applicationOpenURLSourceApplicationAnnotation method. I have changed manually but still its not redirected back to authenticate page

applicationOpenURLSourceApplicationAnnotation(app: UIApplication, url: NSURL, sourceApp: string, annotation: any): boolean {

    if (url.scheme.toLowerCase() === scheme) {

        let client:TnsOAuthClient = new TnsOAuthClient('identityServer');
        client.resumeWithUrl(url.absoluteString);
        return true;
      } else {
        this.handleRouting(url);
      }
  }

@eduardocalixtokorp Could you please provide the workaround?

eduardocalixtokorp commented 3 years ago

It's something like this:

import { AppURL, handleOpenURL } from 'nativescript-urlhandler';
// ...
var iosOauthRedirectFn: (url: string) => void;
handleOpenURL((appURL: AppURL) => {
    if (isIOS && iosOauthRedirectFn) {
        iosOauthRedirectFn(appURL.toString());
    }
});
// ...
iosOauthRedirectFn = ((url) => {
    if (this.oauthClient?.resumeWithUrl) {
        this.oauthClient.resumeWithUrl(url);
    }
});
this.oauthClient.loginWithCompletion(completion);

Notice that you should follow nativescript url handler guide

Thisgio commented 3 years ago

Thanks @eduardocalixtokorp. It works! Life saver :)

sikemullivan commented 3 years ago

I wasn't able to get nativescript-urlhandler working on NativeScript 8. Is there another work around for this?