This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
forked from brokenhandsio/vapor-oauth
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from vamsii777/feature/jwk
Enhancing Security with JWKS Integration for OAuth 2.0 and OpenID Connect
- Loading branch information
Showing
52 changed files
with
969 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Foundation | ||
import Vapor | ||
import JWTKit | ||
|
||
public final class JWKS: Content { | ||
public let keys: [JWK] | ||
public init(keys: [JWK]) { | ||
self.keys = keys | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,79 @@ | ||
import Vapor | ||
|
||
public final class OAuthUser: Authenticatable, Extendable, Encodable { | ||
public struct OAuthUser: Authenticatable, Content { | ||
public var id: String? | ||
public let username: String | ||
public let emailAddress: String? | ||
public var password: String | ||
|
||
public var id: String? | ||
|
||
// OpenID Connect specific attributes | ||
public var name: String? | ||
public var givenName: String? | ||
public var familyName: String? | ||
public var middleName: String? | ||
public var nickname: String? | ||
public var preferredUserName: String? | ||
public var profile: String? | ||
public var picture: String? | ||
public var website: String? | ||
public var emailVerified: Bool? | ||
public var gender: String? | ||
public var birthdate: String? | ||
public var zoneinfo: String? | ||
public var locale: String? | ||
public var phoneNumber: String? | ||
public var phoneNumberVerified: Bool? | ||
public var address: Address? | ||
public var extend: [String: String]? | ||
public var updatedAt: Date? | ||
|
||
public var extend: Extend = .init() | ||
|
||
public init(userID: String? = nil, username: String, emailAddress: String?, password: String, | ||
name: String? = nil, givenName: String? = nil, familyName: String? = nil, middleName: String? = nil, | ||
nickname: String? = nil, profile: String? = nil, picture: String? = nil, website: String? = nil, | ||
gender: String? = nil, birthdate: String? = nil, zoneinfo: String? = nil, locale: String? = nil, | ||
phoneNumber: String? = nil, updatedAt: Date? = nil) { | ||
nickname: String? = nil, preferredUserName: String? = nil, profile: String? = nil, picture: String? = nil, | ||
website: String? = nil, emailVerified: Bool? = nil, gender: String? = nil, birthdate: String? = nil, | ||
zoneinfo: String? = nil, locale: String? = nil, phoneNumber: String? = nil, phoneNumberVerified: Bool? = nil, | ||
address: Address? = nil, extend: [String: String]? = nil, updatedAt: Date? = nil) { | ||
self.id = userID | ||
self.username = username | ||
self.emailAddress = emailAddress | ||
self.password = password | ||
self.id = userID | ||
self.name = name | ||
self.givenName = givenName | ||
self.familyName = familyName | ||
self.middleName = middleName | ||
self.nickname = nickname | ||
self.preferredUserName = preferredUserName | ||
self.profile = profile | ||
self.picture = picture | ||
self.website = website | ||
self.emailVerified = emailVerified | ||
self.gender = gender | ||
self.birthdate = birthdate | ||
self.zoneinfo = zoneinfo | ||
self.locale = locale | ||
self.phoneNumber = phoneNumber | ||
self.phoneNumberVerified = phoneNumberVerified | ||
self.address = address | ||
self.extend = extend | ||
self.updatedAt = updatedAt | ||
} | ||
} | ||
|
||
public struct Address: Content { | ||
public var formatted: String? | ||
public var streetAddress: String? | ||
public var locality: String? | ||
public var region: String? | ||
public var postalCode: String? | ||
public var country: String? | ||
|
||
public init(formatted: String? = nil, streetAddress: String? = nil, locality: String? = nil, | ||
region: String? = nil, postalCode: String? = nil, country: String? = nil) { | ||
self.formatted = formatted | ||
self.streetAddress = streetAddress | ||
self.locality = locality | ||
self.region = region | ||
self.postalCode = postalCode | ||
self.country = country | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import Vapor | ||
import JWTKit | ||
|
||
public protocol AccessToken { | ||
var tokenString: String { get } | ||
public protocol AccessToken: JWTPayload { | ||
var jti: String { get } | ||
var clientID: String { get } | ||
var userID: String? { get } | ||
var scopes: [String]? { get } | ||
var scopes: String? { get } | ||
var expiryTime: Date { get } | ||
} | ||
|
||
// Providing a default implementation of verify(using:) for AccessToken | ||
extension AccessToken { | ||
public func verify(using signer: JWTSigner) throws { | ||
try expiryTime.verifyNotExpired() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import JWTKit | ||
import Vapor | ||
|
||
public protocol IDToken { | ||
var tokenString: String { get set } | ||
var issuer: String { get set } | ||
var subject: String { get set } | ||
var audience: [String] { get set } | ||
var expiration: Date { get set } | ||
var issuedAt: Date { get set } | ||
var nonce: String? { get set } | ||
var authTime: Date? { get set } | ||
public protocol IDToken: JWTPayload { | ||
var jti: String { get set } // JWT ID, a unique identifier for the token | ||
var iss: String { get set } // Issuer | ||
var sub: String { get set } // Subject | ||
var aud: [String] { get set } // Audience | ||
var exp: Date { get set } // Expiration Time | ||
var iat: Date { get set } // Issued At | ||
var nonce: String? { get set } // Nonce, used in OpenID Connect | ||
var authTime: Date? { get set } // Authentication Time | ||
// Additional claims can be added as needed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import Vapor | ||
import JWTKit | ||
|
||
public protocol RefreshToken { | ||
var tokenString: String { get set } | ||
public protocol RefreshToken: JWTPayload { | ||
var jti: String { get set } | ||
var clientID: String { get set } | ||
var userID: String? { get set } | ||
var scopes: [String]? { get set } | ||
var scopes: String? { get set } | ||
var exp: Date { get } | ||
} | ||
|
||
// Implementing verify(using:) for the RefreshToken protocol | ||
extension RefreshToken { | ||
public func verify(using signer: JWTSigner) throws { | ||
try exp.verifyNotExpired() | ||
} | ||
} |
Oops, something went wrong.