From f1caa38166fcdeb9e331a5e68bce014dd28a3480 Mon Sep 17 00:00:00 2001 From: Kevin McKee Date: Tue, 3 Jun 2025 10:51:18 -0700 Subject: [PATCH 1/3] Updating README --- OAuthSample/ContentView.swift | 53 ++++++++++++++++++++++++++--------- README.md | 6 +++- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/OAuthSample/ContentView.swift b/OAuthSample/ContentView.swift index a48f80d..05a3b54 100644 --- a/OAuthSample/ContentView.swift +++ b/OAuthSample/ContentView.swift @@ -26,15 +26,23 @@ struct ContentView: View { switch oauth.state { case .empty: providerList - case .authorizing(let provider, _): - Text("Authorizing [\(provider.id)]") + case .authorizing(let provider, let grantType): + Text("Authorizing [\(provider.id)] with [\(grantType.rawValue)]") case .requestingAccessToken(let provider): Text("Requesting Access Token [\(provider.id)]") case .requestingDeviceCode(let provider): Text("Requesting Device Code [\(provider.id)]") - case .authorized(let auth): - Button("Authorized [\(auth.issuer)]") { - oauth.clear() + case .authorized(let provider, _): + HStack { + Button("Authorized [\(provider.id)]") { + oauth.clear() + } + Button { + oauth.authorize(provider: provider, grantType: .refreshToken) + } label: { + Image(systemName: "arrow.clockwise") + } + } case .receivedDeviceCode(_, let deviceCode): Text("To login, visit") @@ -56,7 +64,8 @@ struct ContentView: View { List(oauth.providers) { provider in Button(provider.id) { // Start the authorization flow (use .deviceCode for tvOS) - oauth.authorize(provider: provider, grantType: .authorizationCode) + let grantType: OAuth.GrantType = .pkce(.init()) + oauth.authorize(provider: provider, grantType: grantType) } } } @@ -67,16 +76,32 @@ struct ContentView: View { switch state { case .empty, .requestingAccessToken, .requestingDeviceCode: break - case .authorizing, .receivedDeviceCode: - #if !os(tvOS) - openWindow(id: "oauth") - #endif - case .authorized: - #if !os(tvOS) - dismissWindow(id: "oauth") - #endif + case .authorizing(_, let grantType): + switch grantType { + case .authorizationCode, .pkce, .deviceCode: + openWebView() + case .clientCredentials, .refreshToken: + break + } + case .receivedDeviceCode: + openWebView() + case .authorized: + dismissWebView() } } + + private func openWebView() { + #if !os(tvOS) + openWindow(id: "oauth") + #endif + } + + private func dismissWebView() { + #if !os(tvOS) + dismissWindow(id: "oauth") + #endif + } + } #Preview { diff --git a/README.md b/README.md index 29b6b9d..975ce3f 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,13 @@ ![Xcode 16.3+](https://img.shields.io/badge/Xcode-16.3%2B-gold.svg) ![Swift 6.0+](https://img.shields.io/badge/Swift-6.0%2B-tomato.svg) ![iOS 18.0+](https://img.shields.io/badge/iOS-18.0%2B-crimson.svg) -![visionOS 2.0+](https://img.shields.io/badge/visionOS-2.0%2B-magenta.svg) ![macOS 15.0+](https://img.shields.io/badge/macOS-15.0%2B-skyblue.svg) +![tvOS 18.0+](https://img.shields.io/badge/tvOS-18.0%2B-blue.svg) +![visionOS 2.0+](https://img.shields.io/badge/visionOS-2.0%2B-magenta.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-indigo.svg)](https://opensource.org/licenses/MIT) # OAuthKit Sample Sample Swift Application for using the [OAuthKit](https://github.com/codefiesta/OAuthKit) Library. + +## Configuration +This sample application provides a number of pre-configured OAuth 2.0 providers listed in the [outh.json](https://github.com/codefiesta/OAuthSample/blob/main/OAuthSample/Preview%20Content/oauth.json) file. You'll need to replace the clientID and clientSecret values with your own to run the sample application. From d5f7c9786773edb7fc885886a32e86c2f7b70e15 Mon Sep 17 00:00:00 2001 From: Kevin McKee Date: Tue, 3 Jun 2025 10:57:37 -0700 Subject: [PATCH 2/3] Bumping OAuthKit version to 1.0.0 --- OAuthSample.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OAuthSample.xcodeproj/project.pbxproj b/OAuthSample.xcodeproj/project.pbxproj index 2ecd5d3..9641afd 100644 --- a/OAuthSample.xcodeproj/project.pbxproj +++ b/OAuthSample.xcodeproj/project.pbxproj @@ -394,7 +394,7 @@ repositoryURL = "https://github.com/codefiesta/OAuthKit.git"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 0.1.1; + minimumVersion = 1.0.0; }; }; /* End XCRemoteSwiftPackageReference section */ From d28a61e3515c5bb697a8a86ece470ebceafca1d7 Mon Sep 17 00:00:00 2001 From: Kevin McKee Date: Tue, 3 Jun 2025 11:02:58 -0700 Subject: [PATCH 3/3] WIP on wip Setting debug to true for sample providers. --- OAuthSample/Preview Content/oauth.json | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/OAuthSample/Preview Content/oauth.json b/OAuthSample/Preview Content/oauth.json index 0a12ddd..0b60302 100644 --- a/OAuthSample/Preview Content/oauth.json +++ b/OAuthSample/Preview Content/oauth.json @@ -10,7 +10,8 @@ "scope": [ "user", "repo" - ] + ], + "debug": true, }, { "id": "Google", @@ -24,7 +25,8 @@ "email", "profile", "openid" - ] + ], + "debug": true, }, { "id": "Microsoft", @@ -37,7 +39,8 @@ "email", "profile", "openid" - ] + ], + "debug": true, }, { "id": "Slack", @@ -49,7 +52,8 @@ "customUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15", "scope": [ "incoming-webhook" - ] + ], + "debug": true, }, { "id": "LinkedIn", @@ -63,7 +67,8 @@ "email", "profile", "openid" - ] + ], + "debug": true, } ]