Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OAuthSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
53 changes: 39 additions & 14 deletions OAuthSample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}
}
}
Expand All @@ -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 {
Expand Down
15 changes: 10 additions & 5 deletions OAuthSample/Preview Content/oauth.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"scope": [
"user",
"repo"
]
],
"debug": true,
},
{
"id": "Google",
Expand All @@ -24,7 +25,8 @@
"email",
"profile",
"openid"
]
],
"debug": true,
},
{
"id": "Microsoft",
Expand All @@ -37,7 +39,8 @@
"email",
"profile",
"openid"
]
],
"debug": true,
},
{
"id": "Slack",
Expand All @@ -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",
Expand All @@ -63,7 +67,8 @@
"email",
"profile",
"openid"
]
],
"debug": true,
}

]
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.