Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS is not sign in due to URL scheme #156

Open
eduardocalixtokorp opened this issue Mar 29, 2021 · 6 comments
Open

iOS is not sign in due to URL scheme #156

eduardocalixtokorp opened this issue Mar 29, 2021 · 6 comments

Comments

@eduardocalixtokorp
Copy link

eduardocalixtokorp commented Mar 29, 2021

Which platform(s) does your issue occur on?

  • iOS 13 / 14 versions emulator

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

  • CLI: 7.0.11
  • Plugin(s):
"dependencies": {
    "@angular/animations": "~10.1.0",
    "@angular/common": "~10.1.0",
    "@angular/compiler": "~10.1.0",
    "@angular/core": "~10.1.0",
    "@angular/forms": "~10.1.0",
    "@angular/platform-browser": "~10.1.0",
    "@angular/platform-browser-dynamic": "~10.1.0",
    "@angular/router": "~10.1.0",
    "@danvick/ngx-translate-nativescript-loader": "^3.0.0",
    "@nativescript-community/sentry": "^2.0.8",
    "@nativescript-community/ui-pager": "13.0.0-alpha.14",
    "@nativescript/angular": "10.1.7",
    "@nativescript/core": "7.0.13",
    "@nativescript/datetimepicker": "^2.0.4",
    "@nativescript/theme": "~2.3.0",
    "@nativescript/unit-test-runner": "^1.0.2",
    "@ngx-translate/core": "^13.0.0",
    "@ngx-translate/http-loader": "^6.0.0",
    "@nstudio/nativescript-cardview": "^2.0.0",
    "@nstudio/nativescript-loading-indicator": "^4.0.0",
    "angular2-uuid": "^1.1.1",
    "http-mockserver": "^2.2.2",
    "jwt-decode": "^3.1.2",
    "nativescript-barcodescanner": "^3.4.2",
    "nativescript-oauth2": "^3.0.3",
    "nativescript-speech-recognition": "^1.5.0",
    "nativescript-sqlite": "^2.6.3",
    "nativescript-toasty-ns-7": "^14.0.0",
    "nativescript-ui-calendar": "^7.0.2",
    "nativescript-ui-chart": "^8.0.2",
    "nativescript-ui-listview": "9.0.4",
    "nativescript-ui-sidedrawer": "9.0.2",
    "nativescript-urlhandler": "^1.3.0",
    "reflect-metadata": "~0.1.12",
    "rxjs": "^6.6.0",
    "zone.js": "~0.11.1"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~10.1.0",
    "@nativescript/android": "7.0.1",
    "@nativescript/ios": "7.0.6",
    "@nativescript/types": "~7.0.0",
    "@nativescript/webpack": "~3.0.0",
    "@ngtools/webpack": "~10.1.0",
    "@types/jasmine": "3.5.14",
    "@types/node": "~10.12.18",
    "jasmine": "~3.3.1",
    "jasmine-core": "~3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "json-server": "^0.16.3",
    "karma": "5.2.3",
    "karma-jasmine": "4.0.1",
    "karma-nativescript-launcher": "0.4.0",
    "karma-webpack": "3.0.5",
    "nativescript-dev-appium": "6.1.3",
    "typescript": "~3.9.0"
  }

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
Copy link

Thisgio commented Jul 13, 2021

Still no fix? @eduardocalixtokorp

@eduardocalixtokorp
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link

Thisgio commented Jul 14, 2021

Thanks @eduardocalixtokorp. It works! Life saver :)

@sikemullivan
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants