[GH-ISSUE #646] How to implement in app browser? #425

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

Originally created by @1hbb on GitHub (Feb 24, 2021).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/646

Description:

This code works perfect but i want to open authorize page internal browser. How can i achieve this ?


let oauthswift = OAuth2Swift(
            consumerKey: "**********",
            consumerSecret: "***********",
            authorizeUrl: "https://www.reddit.com/api/v1/authorize.compact",
            accessTokenUrl: "https://www.reddit.com/api/v1/access_token",
            responseType: "code",
            contentType: "application/json"
        )
        self.oauthswift = oauthswift
        oauthswift.accessTokenBasicAuthentification = true

        let state = generateState(withLength: 20)
        _ = oauthswift.authorize(
            withCallbackURL: URL(string: "SwiftReddit://oauth-callback/reddit")!, scope: "read,identity,edit,flair,history,modconfig,modflair,modlog,modposts,modwiki,mysubreddits,privatemessages,report,save,submit,subscribe,vote,wikiedit,wikiread", state: state, parameters: ["duration": "permanent"]
        ) { result in
            switch result {
            case .success(let (credential, _, _)):
                print("Reddit Toke: ", credential.oauthToken)
            case .failure(let error):
                print(error.description)
            }
        }

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

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • 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:

  • 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

Originally created by @1hbb on GitHub (Feb 24, 2021). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/646 ### Description: This code works perfect but i want to open authorize page internal browser. How can i achieve this ? ```swift let oauthswift = OAuth2Swift( consumerKey: "**********", consumerSecret: "***********", authorizeUrl: "https://www.reddit.com/api/v1/authorize.compact", accessTokenUrl: "https://www.reddit.com/api/v1/access_token", responseType: "code", contentType: "application/json" ) self.oauthswift = oauthswift oauthswift.accessTokenBasicAuthentification = true let state = generateState(withLength: 20) _ = oauthswift.authorize( withCallbackURL: URL(string: "SwiftReddit://oauth-callback/reddit")!, scope: "read,identity,edit,flair,history,modconfig,modflair,modlog,modposts,modwiki,mysubreddits,privatemessages,report,save,submit,subscribe,vote,wikiedit,wikiread", state: state, parameters: ["duration": "permanent"] ) { result in switch result { case .success(let (credential, _, _)): print("Reddit Toke: ", credential.oauthToken) case .failure(let error): print(error.description) } } ``` ### OAuth Provider? (Twitter, Github, ..): ### OAuth Version: - [ ] Version 1 - [x] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [ ] CocoaPods - [x] Swift Package Manager - [ ] Manually ### Library version: - [ ] head - [x] v2.1.0 - [ ] v2.0.0 - [ ] v1.4.1 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [x] 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
kerem closed this issue 2026-03-03 16:48:34 +03:00
Author
Owner

@phimage commented on GitHub (Feb 24, 2021):

internal browser?

custom handler doc could be found here
https://github.com/OAuthSwift/OAuthSwift#handle-authorize-url

in App Store internal webview for auth is not welcomed, prefer use SafariURLHandler

<!-- gh-comment-id:785238179 --> @phimage commented on GitHub (Feb 24, 2021): internal browser? custom handler doc could be found here https://github.com/OAuthSwift/OAuthSwift#handle-authorize-url in App Store internal webview for auth is not welcomed, prefer use SafariURLHandler
Author
Owner

@1hbb commented on GitHub (Feb 24, 2021):

internal browser?

I'm sorry that I misrepresented it. I meant aswebauthenticationsession. Can u give little working example. I searched all the demo app source code but could not find a clear example.

<!-- gh-comment-id:785257184 --> @1hbb commented on GitHub (Feb 24, 2021): > internal browser? I'm sorry that I misrepresented it. I meant aswebauthenticationsession. Can u give little working example. I searched all the demo app source code but could not find a clear example.
Author
Owner

@1hbb commented on GitHub (Feb 24, 2021):

I got it like below. Thanks for this great package 👍🏻

func getURLHandler() -> OAuthSwiftURLHandlerType {
        if #available(iOS 9.0, *) {
            let handler = SafariURLHandler(viewController: self, oauthSwift: self.oauthswift!)
            handler.presentCompletion = {
                print("Safari presented")
            }
            handler.dismissCompletion = {
                print("Safari dismissed")
            }
            return handler
        }
        return OAuthSwiftOpenURLExternally.sharedInstance
    }

oauthswift.authorizeURLHandler = getURLHandler()

<!-- gh-comment-id:785278784 --> @1hbb commented on GitHub (Feb 24, 2021): I got it like below. Thanks for this great package 👍🏻 ```swift func getURLHandler() -> OAuthSwiftURLHandlerType { if #available(iOS 9.0, *) { let handler = SafariURLHandler(viewController: self, oauthSwift: self.oauthswift!) handler.presentCompletion = { print("Safari presented") } handler.dismissCompletion = { print("Safari dismissed") } return handler } return OAuthSwiftOpenURLExternally.sharedInstance } oauthswift.authorizeURLHandler = getURLHandler() ```
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#425
No description provided.