Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device Code Flow into Vapor OAuth #17

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a8d4e9f
Implement and integrate device code grant type in OAuth flow
vamsii777 Aug 24, 2023
e96d61c
Add scope validation to DeviceCodeTokenHandler
vamsii777 Aug 24, 2023
7466495
Integrate DeviceCodeTokenHandler into TokenHandler to support device …
vamsii777 Aug 24, 2023
7b0a3b8
Refactor TokenManager protocol by removing device code-related methods
vamsii777 Aug 24, 2023
fa30cca
Extend CodeManager protocol to include methods for handling device codes
vamsii777 Aug 24, 2023
b9c3e1a
Add expiration check for device code in DeviceCodeTokenHandler
vamsii777 Aug 24, 2023
564f76e
Refactor TokenHandler based on DeviceCodeTokenHandler
vamsii777 Aug 24, 2023
f2e7272
Update OAuthResponseParameters.ErrorType with expiredToken
vamsii777 Aug 24, 2023
9f40c9c
Update EmptyCodeManager to conform to the updated CodeManager protocol
vamsii777 Aug 24, 2023
f74ba60
Handle expired device code in DeviceCodeTokenHandler
vamsii777 Aug 24, 2023
5a45fde
Fix all test cases related to device code token handling
vamsii777 Aug 24, 2023
b558124
Implement PKCE for Vapor OAuth (#1)
vamsii777 Dec 23, 2023
02dd267
Update Vapor package to version 4.90.0
vamsii777 Jan 6, 2024
ede89f6
Merge pull request #9 from vamsii777/patch
vamsii777 Jan 6, 2024
f21676d
Refactor: Remove comments and update doc comments for CodeManager
vamsii777 Jan 10, 2024
04cac65
Refactor: Update OAuthClient properties for Sendable compatibility
vamsii777 Jan 10, 2024
9788cb4
Refactor: Updated StaticClientRetriever to work with concurrent access
vamsii777 Jan 10, 2024
a1398bf
Refactor OAuthHelper+remote.swift
vamsii777 Jan 10, 2024
999f9fb
Remove unnecessary file headers and imports
vamsii777 Jan 10, 2024
25ab030
Add Sendable conformance to OAuthFlowType
vamsii777 Jan 10, 2024
6e4ed87
Add PKCEValidator for PKCE validation
vamsii777 Jan 10, 2024
db1d572
Add nonce parameter to generateCode function
vamsii777 Jan 10, 2024
7f319da
Refactor async methods in OAuthHelper+remote.swift
vamsii777 Jan 10, 2024
2fa53e6
Add token generation methods to TokenManager protocol
vamsii777 Jan 10, 2024
07471ad
Add nonce parameter to code generation
vamsii777 Jan 10, 2024
711e9e6
Add nonce parameter to generateCode method for tests
vamsii777 Jan 10, 2024
2759152
Merge pull request #10 from vamsii777/patch
vamsii777 Jan 10, 2024
57e6fd0
Refactor OAuth models to use structs instead of classes
vamsii777 Jan 11, 2024
fd05d53
Refactor OAuthUser struct extend
vamsii777 Jan 11, 2024
8605265
Refactor OAuthClient and OAuthResourceServer models
vamsii777 Jan 11, 2024
6268dee
Update Vapor package to version 4.91.1
vamsii777 Jan 11, 2024
a232797
Merge pull request #12 from vamsii777/patch
vamsii777 Jan 11, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
ubuntu_test:
name: Ubuntu Build & Test
runs-on: ubuntu-22.04
container: swift:5.7.3-jammy
container: swift:5.9.2-jammy
steps:
- uses: actions/checkout@v3
- name: Build
Expand All @@ -22,8 +22,8 @@ jobs:
macos_test:
name: macOS Build & Test
env:
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
runs-on: macos-12
DEVELOPER_DIR: /Applications/Xcode_15.1.app/Contents/Developer
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- name: Build
Expand Down
97 changes: 53 additions & 44 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,152 +5,161 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/async-http-client.git",
"state" : {
"revision" : "fc510a39cff61b849bf5cdff17eb2bd6d0777b49",
"version" : "1.11.5"
"revision" : "5ccda442f103792d67680aefc8d0a87392fbd66c",
"version" : "1.20.0"
}
},
{
"identity" : "async-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/async-kit.git",
"state" : {
"revision" : "c3329e444bafbb12d1d312af9191be95348a8175",
"version" : "1.13.0"
"revision" : "7ece208cd401687641c88367a00e3ea2b04311f1",
"version" : "1.19.0"
}
},
{
"identity" : "console-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/console-kit.git",
"state" : {
"revision" : "a7e67a1719933318b5ab7eaaed355cde020465b1",
"version" : "4.5.0"
"revision" : "a7dd7001196d39b758e4990ec0f26f80162f4c84",
"version" : "4.14.0"
}
},
{
"identity" : "jwt-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/jwt-kit.git",
"state" : {
"revision" : "cd0fe3af36764e876182137c3132a6d8459e1867",
"version" : "4.13.1"
}
},
{
"identity" : "multipart-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/multipart-kit.git",
"state" : {
"revision" : "0d55c35e788451ee27222783c7d363cb88092fab",
"version" : "4.5.2"
"revision" : "12ee56f25bd3fc4c2d09c2aa16e69de61dc786e8",
"version" : "4.6.0"
}
},
{
"identity" : "routing-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/routing-kit.git",
"state" : {
"revision" : "ffac7b3a127ce1e85fb232f1a6271164628809ad",
"version" : "4.6.0"
"revision" : "2a92a7eac411a82fb3a03731be5e76773ebe1b3e",
"version" : "4.9.0"
}
},
{
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-algorithms.git",
"state" : {
"revision" : "b14b7f4c528c942f121c8b860b9410b2bf57825e",
"version" : "1.0.0"
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
"version" : "1.2.0"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "919eb1d83e02121cdb434c7bfc1f0c66ef17febe",
"version" : "1.0.2"
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
"version" : "1.2.0"
}
},
{
"identity" : "swift-backtrace",
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/swift-backtrace.git",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "f25620d5d05e2f1ba27154b40cafea2b67566956",
"version" : "1.3.3"
"revision" : "d029d9d39c87bed85b1c50adee7c41795261a192",
"version" : "1.0.6"
}
},
{
"identity" : "swift-collections",
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "f504716c27d2e5d4144fa4794b12129301d17729",
"version" : "1.0.3"
"revision" : "b51f1d6845b353a2121de1c6a670738ec33561a6",
"version" : "3.1.0"
}
},
{
"identity" : "swift-crypto",
"identity" : "swift-http-types",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"location" : "https://github.com/apple/swift-http-types",
"state" : {
"revision" : "d9825fa541df64b1a7b182178d61b9a82730d01f",
"version" : "2.1.0"
"revision" : "1827dc94bdab2eb5f2fc804e9b0cb43574282566",
"version" : "1.0.2"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "6fe203dc33195667ce1759bf0182975e4653ba1c",
"version" : "1.4.4"
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
}
},
{
"identity" : "swift-metrics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-metrics.git",
"state" : {
"revision" : "53be78637ecd165d1ddedc4e20de69b8f43ec3b7",
"version" : "2.3.2"
"revision" : "971ba26378ab69c43737ee7ba967a896cb74c0d1",
"version" : "2.4.1"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "b4e0a274f7f34210e97e2f2c50ab02a10b549250",
"version" : "2.41.1"
"revision" : "702cd7c56d5d44eeba73fdf83918339b26dc855c",
"version" : "2.62.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "6c84d247754ad77487a6f0694273b89b83efd056",
"version" : "1.14.0"
"revision" : "798c962495593a23fdea0c0c63fd55571d8dff51",
"version" : "1.20.0"
}
},
{
"identity" : "swift-nio-http2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "f9ab1c94c80d568efd762d2a638f25162691d766",
"version" : "1.22.1"
"revision" : "3bd9004b9d685ed6b629760fc84903e48efec806",
"version" : "1.29.0"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "ba7c0d7f82affc518147ea61d240330bf7f7ea9b",
"version" : "2.22.1"
"revision" : "320bd978cceb8e88c125dcbb774943a92f6286e9",
"version" : "2.25.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "4e02d9cf35cabfb538c96613272fb027dd0c8692",
"version" : "1.13.1"
"revision" : "ebf8b9c365a6ce043bf6e6326a04b15589bd285e",
"version" : "1.20.0"
}
},
{
Expand All @@ -167,17 +176,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/vapor.git",
"state" : {
"revision" : "dda0de537e7906414dccd551e77095be1e34e3da",
"version" : "4.65.2"
"revision" : "0680f9f6bfab7100cd585b3186740ee7860c983e",
"version" : "4.91.1"
}
},
{
"identity" : "websocket-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/websocket-kit.git",
"state" : {
"revision" : "2d9d2188a08eef4a869d368daab21b3c08510991",
"version" : "2.6.1"
"revision" : "53fe0639a98903858d0196b699720decb42aee7b",
"version" : "2.14.0"
}
}
],
Expand Down
12 changes: 9 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.9
import PackageDescription

let package = Package(
Expand All @@ -13,12 +13,18 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0")
.package(url: "https://github.com/vapor/vapor.git", from: "4.90.0"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.1.0"),
.package(url: "https://github.com/vapor/jwt-kit.git", from: "4.13.1")
],
targets: [
.target(
name: "VaporOAuth",
dependencies: [.product(name: "Vapor", package: "vapor")]
dependencies: [
.product(name: "Vapor", package: "vapor"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "JWTKit", package: "jwt-kit")
]
),
.testTarget(name: "VaporOAuthTests", dependencies: [
.target(name: "VaporOAuth"),
Expand Down
23 changes: 18 additions & 5 deletions Sources/VaporOAuth/DefaultImplementations/EmptyCodeManager.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
public struct EmptyCodeManager: CodeManager {
public init() {}

public func getCode(_ code: String) -> OAuthCode? {
return nil
}

public func generateCode(
userID: String,
clientID: String,
redirectURI: String,
scopes: [String]?
) throws -> String {
scopes: [String]?,
codeChallenge: String?,
codeChallengeMethod: String?,
nonce: String?
) async throws -> String {
return ""
}

public func codeUsed(_ code: OAuthCode) {}

public func getDeviceCode(_ deviceCode: String) -> OAuthDeviceCode? {
return nil
}

public func generateDeviceCode(userID: String, clientID: String, scopes: [String]?) async throws -> String {
return ""
}

public func deviceCodeUsed(_ deviceCode: OAuthDeviceCode) {}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
public struct StaticClientRetriever: ClientRetriever {

let clients: [String: OAuthClient]

private let clients: [String: OAuthClient]

public init(clients: [OAuthClient]) {
self.clients = clients.reduce([String: OAuthClient]()) { (dict, client) -> [String: OAuthClient] in
var dict = dict
self.clients = clients.reduce(into: [String: OAuthClient]()) { (dict, client) in
dict[client.clientID] = client
return dict
}
}

public func getClient(clientID: String) async throws -> OAuthClient? {
public func getClient(clientID: String) throws -> OAuthClient? {
return clients[clientID]
}
}
Loading