Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 8abbb29

Browse files
committed
Rename PKCE Mode to Method to be in line with spec
This also resulted in renaming the computed variable `method` to `testMethodURLQueryParameterValue` because `Method.method` would have been confusing. The new name also better reflects where the value is meant to be used.
1 parent e963a39 commit 8abbb29

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

WordPressAuthenticator/GoogleSignIn/URL+GoogleSignIn.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extension URL {
1010
let queryItems = [
1111
("client_id", clientId),
1212
("code_challenge", pkce.codeCallenge),
13-
("code_challenge_method", pkce.mode.method),
13+
("code_challenge_method", pkce.method.urlQueryParameterValue),
1414
("redirect_uri", redirectURI(from: clientId)),
1515
("response_type", "code"),
1616
// TODO: We might want to add some of these or them configurable

WordPressAuthenticator/OAuth/ProofKeyForCodeExchange.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
// Note: The common abbreviation of "Proof Key for Code Exchange" is PKCE and is pronounced "pixy".
1414
struct ProofKeyForCodeExchange {
1515

16-
enum Mode {
16+
enum Method {
1717
case s256
1818
case plain
1919

20-
var method: String {
20+
var urlQueryParameterValue: String {
2121
switch self {
2222
case .plain: return "plain"
2323
case .s256: return "S256"
@@ -26,15 +26,15 @@ struct ProofKeyForCodeExchange {
2626
}
2727

2828
let codeVerifier: String
29-
let mode: Mode
29+
let method: Method
3030

31-
init(codeVerifier: String, mode: Mode) {
31+
init(codeVerifier: String, method: Method) {
3232
self.codeVerifier = codeVerifier
33-
self.mode = mode
33+
self.method = method
3434
}
3535

3636
var codeCallenge: String {
37-
switch mode {
37+
switch method {
3838
case .s256:
3939
// TODO: code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
4040
fatalError()

WordPressAuthenticatorTests/GoogleSignIn/OAuthRequestBody+GoogleSignInTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import XCTest
44
class OAuthRequestBodyGoogleSignInTests: XCTestCase {
55

66
func testGoogleSignInTokenRequestBody() throws {
7-
let pkce = ProofKeyForCodeExchange(codeVerifier: "test", mode: .plain)
7+
let pkce = ProofKeyForCodeExchange(codeVerifier: "test", method: .plain)
88
let body = OAuthTokenRequestBody.googleSignInRequestBody(
99
clientId: "com.app.123-abc",
1010
authCode: "codeValue",

WordPressAuthenticatorTests/GoogleSignIn/URL+GoogleSignInTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import XCTest
44
class URLGoogleSignInTests: XCTestCase {
55

66
func testGoogleSignInAuthURL() throws {
7-
let pkce = ProofKeyForCodeExchange(codeVerifier: "test", mode: .plain)
7+
let pkce = ProofKeyForCodeExchange(codeVerifier: "test", method: .plain)
88
let url = try URL.googleSignInAuthURL(
99
clientId: "123-abc245def.apps.googleusercontent.com",
1010
pkce: pkce
@@ -24,7 +24,7 @@ class URLGoogleSignInTests: XCTestCase {
2424
assertQueryItems(
2525
for: url,
2626
includeItemNamed: "code_challenge_method",
27-
withValue: pkce.mode.method
27+
withValue: pkce.method.urlQueryParameterValue
2828
)
2929
assertQueryItems(
3030
for: url,

WordPressAuthenticatorTests/OAuth/ProofKeyForCodeExchangeTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ProofKeyForCodeExchangeTests: XCTestCase {
55

66
func testCodeChallengeInPlainModeIsTheSameAsCodeVerifier() {
77
XCTAssertEqual(
8-
ProofKeyForCodeExchange(codeVerifier: "abc", mode: .plain).codeCallenge,
8+
ProofKeyForCodeExchange(codeVerifier: "abc", method: .plain).codeCallenge,
99
"abc"
1010
)
1111
}
@@ -14,11 +14,11 @@ class ProofKeyForCodeExchangeTests: XCTestCase {
1414
// TODO:
1515
}
1616

17-
func testModePlainMethod() {
18-
XCTAssertEqual(ProofKeyForCodeExchange.Mode.plain.method, "plain")
17+
func testMethodURLQueryParameterValuePlain() {
18+
XCTAssertEqual(ProofKeyForCodeExchange.Method.plain.urlQueryParameterValue, "plain")
1919
}
2020

21-
func testModeS256Method() {
22-
XCTAssertEqual(ProofKeyForCodeExchange.Mode.s256.method, "S256")
21+
func testMethodURLQueryParameterValueS256() {
22+
XCTAssertEqual(ProofKeyForCodeExchange.Method.s256.urlQueryParameterValue, "S256")
2323
}
2424
}

0 commit comments

Comments
 (0)