[GH-ISSUE #424] Not able to sign in using the latest Google OAuth provider #273

Closed
opened 2026-03-03 16:47:16 +03:00 by kerem · 3 comments
Owner

Originally created by @mervyn777 on GitHub (Dec 16, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/424

Description:

OAuth SignIn doesn't work with the latest Google OAuth process. Now the iOS/Android OAuth clients don't provide the Client Secret without which the library does not successfully fetch the token. If we use Web client instead during registration on Google API console we cannot set the custom callback URI.(Even if we do it throws error during sign in process). Your demo example is outdated and shows a different http schemed redirect URI. Please let me know if I'm missing something.

URL received on app delegate:

<app.bundle.id>:/oauth2redirect?code=4/2O3vlmmgWeJWUrrFSK3ygp3JtN5ioNb7LvHiYJYU&authuser=0&session_state=4d9f34f683268c9198ca81fe302031c1a212784d..70a8&prompt=consent#

Error received:

OAuthSwiftError error -3

OAuth Provider:

Google

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

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

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.2 (Swift 4.0)
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 9.0 (Swift 4.0)

  • 9.0 (Swift 3.2)

  • 8.x (Swift 3.x)

  • 8.0 (Swift 2.3)

  • 7.3.1

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

  • objective c

Originally created by @mervyn777 on GitHub (Dec 16, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/424 ### Description: OAuth SignIn doesn't work with the latest Google OAuth process. Now the iOS/Android OAuth clients don't provide the Client Secret without which the library does not successfully fetch the token. If we use Web client instead during registration on Google API console we cannot set the custom callback URI.(Even if we do it throws error during sign in process). Your demo example is outdated and shows a different http schemed redirect URI. Please let me know if I'm missing something. #### URL received on app delegate: ```<app.bundle.id>:/oauth2redirect?code=4/2O3vlmmgWeJWUrrFSK3ygp3JtN5ioNb7LvHiYJYU&authuser=0&session_state=4d9f34f683268c9198ca81fe302031c1a212784d..70a8&prompt=consent#``` #### Error received: ```OAuthSwiftError error -3``` ### OAuth Provider: Google ### OAuth Version: - [ ] Version 1 - [x] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x] CocoaPods - [ ] Manually ### Library version: - [x] head - [ ] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [x] 9.0 (Swift 4.0) - [ ] 9.0 (Swift 3.2) - [ ] 8.x (Swift 3.x) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem closed this issue 2026-03-03 16:47:17 +03:00
Author
Owner

@phimage commented on GitHub (Dec 16, 2017):

error -3 maybe oauthswift.allowMissingStateCheck = true could help

<!-- gh-comment-id:352169330 --> @phimage commented on GitHub (Dec 16, 2017): error -3 maybe oauthswift.allowMissingStateCheck = true could help
Author
Owner

@mervyn777 commented on GitHub (Dec 18, 2017):

Thanks that helped!

As for the OAuthSwiftURLHandlerType I'm using the built-in SafariURLHandler but how can I get notified if the user cancels the authorization process by pressing Done in the consent screen.

Is it possible to return back this action in the form of failure callback event while requesting authorization? Something like failure?(OAuthSwiftError.cancelled)?

The problem is I'm handling OAuth related functions in a non NSObject class and I cant implement the SFSafariViewControllerDelegate to be notified about user dismissal actions. (I see I can set this delegate to SafariURLHandler.#delegate)

Update:

One quick way I fixed it was by extending SafariURLHandler :

class SafariURLHandler2: SafariURLHandler {
    var userDismissHandler: (() -> Void)?
    
    override func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
        super.safariViewControllerDidFinish(controller)
        userDismissHandler?()
    }
}

But this will require the modifier of func safariViewControllerDidFinish to be open to be overridden.

Let me know if there's a better way to solve this.

<!-- gh-comment-id:352299810 --> @mervyn777 commented on GitHub (Dec 18, 2017): Thanks that helped! As for the `OAuthSwiftURLHandlerType` I'm using the built-in `SafariURLHandler` but how can I get notified if the user cancels the authorization process by pressing `Done` in the consent screen. Is it possible to return back this action in the form of failure callback event while requesting authorization? Something like `failure?(OAuthSwiftError.cancelled)`? The problem is I'm handling OAuth related functions in a non NSObject class and I cant implement the `SFSafariViewControllerDelegate` to be notified about user dismissal actions. (I see I can set this delegate to `SafariURLHandler.#delegate`) Update: One quick way I fixed it was by extending `SafariURLHandler` : ``` class SafariURLHandler2: SafariURLHandler { var userDismissHandler: (() -> Void)? override func safariViewControllerDidFinish(_ controller: SFSafariViewController) { super.safariViewControllerDidFinish(controller) userDismissHandler?() } } ``` But this will require the modifier of func `safariViewControllerDidFinish` to be open to be overridden. Let me know if there's a better way to solve this.
Author
Owner

@phimage commented on GitHub (Dec 22, 2017):

@mervyn777 do not hesitate to PR if you need add open to some functions

<!-- gh-comment-id:353547165 --> @phimage commented on GitHub (Dec 22, 2017): @mervyn777 do not hesitate to PR if you need add `open` to some functions
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#273
No description provided.