Skip to content

Commit

Permalink
Replace in-line OAuth2 strings with centralized constants
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikPalo committed Nov 26, 2024
1 parent 75b9312 commit a740c6e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
15 changes: 8 additions & 7 deletions Sources/Flows/OAuth2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import Foundation
#if !NO_MODULE_IMPORT
import Base
import Constants
#if os(macOS)
import macOS
#elseif os(iOS) || os(visionOS)
Expand Down Expand Up @@ -358,7 +359,7 @@ open class OAuth2: OAuth2Base {
}

let req = OAuth2AuthRequest(url: (clientConfig.refreshURL ?? clientConfig.tokenURL ?? clientConfig.authorizeURL))
req.params["grant_type"] = "refresh_token"
req.params["grant_type"] = OAuth2GrantTypes.refreshToken

Check failure on line 362 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 362 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 362 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 362 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 362 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope
req.params["refresh_token"] = refreshToken
if let clientId = clientId {
req.params["client_id"] = clientId
Expand Down Expand Up @@ -423,11 +424,11 @@ open class OAuth2: OAuth2Base {
}

let req = OAuth2AuthRequest(url: (clientConfig.tokenURL ?? clientConfig.authorizeURL))
req.params["grant_type"] = "urn:ietf:params:oauth:grant-type:token-exchange"
req.params["grant_type"] = OAuth2GrantTypes.tokenExchange

Check failure on line 427 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 427 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 427 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 427 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 427 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope
req.params["audience"] = audienceClientId
req.params["requested_token_type"] = "urn:ietf:params:oauth:token-type:refresh_token"
req.params["requested_token_type"] = OAuth2TokenTypeIdentifiers.refreshToken

Check failure on line 429 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 429 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 429 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 429 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 429 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope
req.params["subject_token"] = refreshToken
req.params["subject_token_type"] = "urn:ietf:params:oauth:token-type:refresh_token"
req.params["subject_token_type"] = OAuth2TokenTypeIdentifiers.refreshToken

Check failure on line 431 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 431 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 431 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 431 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 431 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope
req.add(params: params)

return req
Expand Down Expand Up @@ -512,12 +513,12 @@ open class OAuth2: OAuth2Base {
}

let req = OAuth2AuthRequest(url: (clientConfig.tokenURL ?? clientConfig.authorizeURL))
req.params["grant_type"] = "urn:ietf:params:oauth:grant-type:token-exchange"
req.params["grant_type"] = OAuth2GrantTypes.tokenExchange

Check failure on line 516 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 516 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 516 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 516 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 516 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope
req.params["resource"] = resourceUrl.appendingPathComponent(resourcePath).absoluteString
req.params["scope"] = clientConfig.scope
req.params["requested_token_type"] = "urn:ietf:params:oauth:token-type:access_token"
req.params["requested_token_type"] = OAuth2TokenTypeIdentifiers.accessToken

Check failure on line 519 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 519 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 519 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 519 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 519 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope
req.params["subject_token"] = accessToken
req.params["subject_token_type"] = "urn:ietf:params:oauth:token-type:access_token"
req.params["subject_token_type"] = OAuth2TokenTypeIdentifiers.accessToken

Check failure on line 521 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 521 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 521 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 521 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope

Check failure on line 521 in Sources/Flows/OAuth2.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2TokenTypeIdentifiers' in scope
req.add(params: params)

return req
Expand Down
3 changes: 2 additions & 1 deletion Sources/Flows/OAuth2ClientCredentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import Foundation
#if !NO_MODULE_IMPORT
import Base
import Constants
#endif


Expand All @@ -30,7 +31,7 @@ Class to handle two-legged OAuth2 requests of the "client_credentials" type.
open class OAuth2ClientCredentials: OAuth2 {

override open class var grantType: String {
return "client_credentials"
return OAuth2GrantTypes.clientCredentials

Check failure on line 34 in Sources/Flows/OAuth2ClientCredentials.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 34 in Sources/Flows/OAuth2ClientCredentials.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 34 in Sources/Flows/OAuth2ClientCredentials.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope
}

override open func doAuthorize(params inParams: OAuth2StringDict? = nil) {
Expand Down
5 changes: 3 additions & 2 deletions Sources/Flows/OAuth2CodeGrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import Foundation
#if !NO_MODULE_IMPORT
import Base
import Constants
#endif


Expand All @@ -34,11 +35,11 @@ key will be embedded into the request body.
open class OAuth2CodeGrant: OAuth2 {

override open class var grantType: String {
return "authorization_code"
return OAuth2GrantTypes.authorizationCode

Check failure on line 38 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 38 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 38 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 38 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 38 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 38 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope
}

override open class var responseType: String? {
return "code"
return OAuth2ResponseTypes.code

Check failure on line 42 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2ResponseTypes' in scope

Check failure on line 42 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2ResponseTypes' in scope

Check failure on line 42 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2ResponseTypes' in scope

Check failure on line 42 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2ResponseTypes' in scope

Check failure on line 42 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2ResponseTypes' in scope

Check failure on line 42 in Sources/Flows/OAuth2CodeGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2ResponseTypes' in scope
}


Expand Down
5 changes: 3 additions & 2 deletions Sources/Flows/OAuth2DeviceGrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import Foundation
#if !NO_MODULE_IMPORT
import Base
import Constants
#endif

/// https://www.ietf.org/rfc/rfc8628.html
open class OAuth2DeviceGrant: OAuth2 {
override open class var grantType: String {
return "urn:ietf:params:oauth:grant-type:device_code"
return OAuth2GrantTypes.deviceCode

Check failure on line 30 in Sources/Flows/OAuth2DeviceGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 30 in Sources/Flows/OAuth2DeviceGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 30 in Sources/Flows/OAuth2DeviceGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope
}

override open class var responseType: String? {
Expand All @@ -39,7 +40,7 @@ open class OAuth2DeviceGrant: OAuth2 {
}

let req = OAuth2AuthRequest(url: (clientConfig.tokenURL ?? clientConfig.authorizeURL))
req.params["device_code"] = deviceCode
req.params["device_code"] = OAuth2GrantTypes.deviceCode

Check failure on line 43 in Sources/Flows/OAuth2DeviceGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 43 in Sources/Flows/OAuth2DeviceGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 43 in Sources/Flows/OAuth2DeviceGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope
req.params["grant_type"] = type(of: self).grantType
req.params["client_id"] = clientId
return req
Expand Down
5 changes: 3 additions & 2 deletions Sources/Flows/OAuth2ImplicitGrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import Foundation
#if !NO_MODULE_IMPORT
import Base
import Constants
#endif


Expand All @@ -30,11 +31,11 @@ Class to handle OAuth2 requests for public clients, such as distributed Mac/iOS
open class OAuth2ImplicitGrant: OAuth2 {

override open class var grantType: String {
return "implicit"
return OAuth2GrantTypes.implicit

Check failure on line 34 in Sources/Flows/OAuth2ImplicitGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 34 in Sources/Flows/OAuth2ImplicitGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 34 in Sources/Flows/OAuth2ImplicitGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope
}

override open class var responseType: String? {
return "token"
return OAuth2ResponseTypes.token

Check failure on line 38 in Sources/Flows/OAuth2ImplicitGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2ResponseTypes' in scope

Check failure on line 38 in Sources/Flows/OAuth2ImplicitGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2ResponseTypes' in scope

Check failure on line 38 in Sources/Flows/OAuth2ImplicitGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2ResponseTypes' in scope
}

override open func handleRedirectURL(_ redirect: URL) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Flows/OAuth2PasswordGrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import Foundation
#if !NO_MODULE_IMPORT
import Base
import Constants
#if os(macOS)
import macOS
#elseif os(iOS) || os(visionOS)
Expand Down Expand Up @@ -53,7 +54,7 @@ If no credentials are set when authorizing, a native controller is shown so that
open class OAuth2PasswordGrant: OAuth2 {

override open class var grantType: String {
return "password"
return OAuth2GrantTypes.password

Check failure on line 57 in Sources/Flows/OAuth2PasswordGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 57 in Sources/Flows/OAuth2PasswordGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-macOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 57 in Sources/Flows/OAuth2PasswordGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-tvOS

error

Cannot find 'OAuth2GrantTypes' in scope

Check failure on line 57 in Sources/Flows/OAuth2PasswordGrant.swift

View workflow job for this annotation

GitHub Actions / results-xcode-tests-iOS

error

Cannot find 'OAuth2GrantTypes' in scope
}

override open class var clientIdMandatory: Bool {
Expand Down

0 comments on commit a740c6e

Please sign in to comment.