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

App Crash when using ASWebAuthenticationSession in iOS 14.5 #664

Open
6 of 21 tasks
RahulTak opened this issue Jun 10, 2021 · 9 comments
Open
6 of 21 tasks

App Crash when using ASWebAuthenticationSession in iOS 14.5 #664

RahulTak opened this issue Jun 10, 2021 · 9 comments

Comments

@RahulTak
Copy link

RahulTak commented Jun 10, 2021

Description:

File: ASWebAuthenticationURLHandler.swift
My app is crash when I am using the

ASWebAuthenticationSession(
            url: url,
            callbackURLScheme: callbackUrlScheme,
            completionHandler: { callback, error in
                if let error = error {
                    let msg = error.localizedDescription.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
                    let errorDomain = (error as NSError).domain
                    let errorCode = (error as NSError).code
                    let urlString = "\(self.callbackUrlScheme):?error=\(msg ?? "UNKNOWN")&error_domain=\(errorDomain)&error_code=\(errorCode)"
                    let url = URL(string: urlString)!
                    #if !OAUTH_APP_EXTENSIONS
                    UIApplication.shared.open(url, options: [:], completionHandler: nil)
                    #endif
                } else if let successURL = callback {
                    #if !OAUTH_APP_EXTENSIONS
                    UIApplication.shared.open(successURL, options: [:], completionHandler: nil)
                    #endif
                }
        })

Then Crash detail is

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The provided scheme is not valid. 
A scheme should not include special characters such as ":" or "/".'

if I replace callbackUrlScheme with callbackUrlScheme .addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) it's working fine.

So please let me know how to add this lines into your package and use into my project.
Or should I have to create the new branch for this is send you the PR for merge into this?

OAuth Provider? (Twitter, Github, ..):

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS : 14.5
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Swift Package Manager
  • Manually

Library version:

  • head
  • v2.1.0
  • v2.0.0
  • v1.4.1
  • other: (Please fill in the version you are using.)

Xcode version:

  • 12.5 (Swift 5.0)

  • 11.4 (Swift 5.2)

  • 11.x (Swift 5.1)

  • 10.x (Swift 5.0)

  • other: (Please fill in the version you are using.)

  • objective c

@phimage
Copy link
Member

phimage commented Jun 10, 2021

you could show code with link

let url = URL(string: urlString)!

first yes ! forecast must be forbidden in OAuthSwift code

I see some edit about that recently, maybe it depend on swift version

@RahulTak
Copy link
Author

@phimage Yes forecast must be forbidden,
but my point is different That app crashing while creating the object of ASWebAuthenticationSession because in this we are sending callbackURLScheme normally.

But we required to send like this callbackUrlScheme.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) I have tested this with my by cloning your package and made this changes

@phimage
Copy link
Member

phimage commented Jun 10, 2021

your value of callbackURLScheme is ?

because you pass it , so you could encode it if very necessary (or not is based to ASWebAuthenticationSession is different)
if you put ":" or "/" in a scheme it's your error maybe?

@RahulTak
Copy link
Author

@phimage yes this is the problem, can you please help me to resolve this ?

@phatblat
Copy link
Collaborator

@RahulTak are you passing a full URL as the callbackScheme? Your scheme should not contain a colon. ASWebAuthenticationSession used to only log an error if you passed a full URL as the scheme but as of 14.5 it crashes

@RahulTak
Copy link
Author

@phimage I am passing the URL like myappSchemeName://authorizedcallback because we need this while popup dismiss.

@phimage
Copy link
Member

phimage commented Jun 10, 2021

that's not a scheme.

an url isscheme://host/path?query#fragment

@RahulTak
Copy link
Author

But myappSchemeName://authorizedcallback this is working fine into the iOS 14.4

@phatblat
Copy link
Collaborator

Yep, it worked for us too in 14.4, but check your logs for the error. What changed in 14.5 is that Apple is now crashing instead of just logging an error.

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

3 participants