[GH-ISSUE #639] SwiftUI support? #419

Open
opened 2026-03-03 16:48:32 +03:00 by kerem · 5 comments
Owner

Originally created by @cacaosteve on GitHub (Dec 16, 2020).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/639

I'm wondering about SwiftUI support?

Originally created by @cacaosteve on GitHub (Dec 16, 2020). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/639 I'm wondering about SwiftUI support?
Author
Owner

@mesopelagique commented on GitHub (Dec 16, 2020):

#626 ?

<!-- gh-comment-id:745816955 --> @mesopelagique commented on GitHub (Dec 16, 2020): #626 ?
Author
Owner

@MoMitch commented on GitHub (Feb 27, 2021):

Issue is:
SwiftUI has a new method of catching callback urls.

Solution: We should have a way to pass in a url response ourselves to the auth object and let it handle it like a normal callback.

<!-- gh-comment-id:787125281 --> @MoMitch commented on GitHub (Feb 27, 2021): Issue is: SwiftUI has a new method of catching callback urls. Solution: We should have a way to pass in a url response ourselves to the auth object and let it handle it like a normal callback.
Author
Owner

@MoMitch commented on GitHub (Feb 27, 2021):

For the meantime, you can do something like this:


                LoginView().onAppear(perform: {
                        // test init our API classes here
                        sharedTwitterClient.logDetails();
                })
                .onOpenURL { url in
                    // TODO: Ensure this is a valid auth login & details
                    
                    print("url",url);
                    isLoggedIn = true;
                    
                    
                    let notification = Notification(name: OAuthSwift.didHandleCallbackURL, object: nil,
                        userInfo: ["OAuthSwiftCallbackNotificationOptionsURLKey": url])
                    
                    
                    NotificationCenter.default.post(notification)
                }

This will re-route all URL's redirecting to the app to the callback function for OAuthSwift.

Note that you probably want to parse it and make sure it's an auth token, and not a deep link etc. first. This was just a quick test.

We call 'logDetails' on sharedTwitterClient which prints out some data, but more importantly instantiates a shared global var and initializes it by connecting to OAuthSwift2 and our twitter details.

<!-- gh-comment-id:787126599 --> @MoMitch commented on GitHub (Feb 27, 2021): For the meantime, you can do something like this: ``` LoginView().onAppear(perform: { // test init our API classes here sharedTwitterClient.logDetails(); }) .onOpenURL { url in // TODO: Ensure this is a valid auth login & details print("url",url); isLoggedIn = true; let notification = Notification(name: OAuthSwift.didHandleCallbackURL, object: nil, userInfo: ["OAuthSwiftCallbackNotificationOptionsURLKey": url]) NotificationCenter.default.post(notification) } ``` This will re-route all URL's redirecting to the app to the callback function for OAuthSwift. Note that you probably want to parse it and make sure it's an auth token, and not a deep link etc. first. This was just a quick test. We call 'logDetails' on sharedTwitterClient which prints out some data, but more importantly instantiates a shared global var and initializes it by connecting to OAuthSwift2 and our twitter details.
Author
Owner

@dadixon commented on GitHub (Apr 17, 2023):

When I run this, I keep getting an error message The operation couldn’t be completed. (OAuthSwiftError error -3.).

<!-- gh-comment-id:1511269673 --> @dadixon commented on GitHub (Apr 17, 2023): When I run this, I keep getting an error message _The operation couldn’t be completed. (OAuthSwiftError error -3.)_.
Author
Owner

@phimage commented on GitHub (Apr 17, 2023):

When I run this, I keep getting an error message The operation couldn’t be completed. (OAuthSwiftError error -3.).

did you try to read the code?

  1. look for -3 -> missingState
  2. look for missingState -> only one instance with a boolean saying to check or not state
  3. set the boolean to true and test
<!-- gh-comment-id:1511277883 --> @phimage commented on GitHub (Apr 17, 2023): > When I run this, I keep getting an error message _The operation couldn’t be completed. (OAuthSwiftError error -3.)_. did you try to read the code? 1. look for -3 -> [missingState](https://github.com/OAuthSwift/OAuthSwift/blob/2384f60031ac824826fc367e6ed963b2c3eae797/Sources/OAuthSwiftError.swift#L51) 2. look for missingState -> [only one instance with a boolean saying to check or not state](https://github.com/OAuthSwift/OAuthSwift/blob/fb65e918099c584edf822b37104d72d369c2a1bb/Sources/OAuth2Swift.swift#L141) 3. [set the boolean to true](https://github.com/OAuthSwift/OAuthSwift/blob/fb65e918099c584edf822b37104d72d369c2a1bb/Sources/OAuth2Swift.swift#L18) and test
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#419
No description provided.