Skip to content

Commit 53609c6

Browse files
committed
refactor: simplify linkIdentityWithIdToken implementation
- Remove private _signInWithIdToken helper method - Inline the implementation directly in linkIdentityWithIdToken - Update test to include Authorization header in expected request - Add session storage setup for linkIdentityWithIdToken test
1 parent 4a989b5 commit 53609c6

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Sources/Auth/AuthClient.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,7 @@ public actor AuthClient {
380380
/// The ID token is verified for validity and a new session is established.
381381
@discardableResult
382382
public func signInWithIdToken(credentials: OpenIDConnectCredentials) async throws -> Session {
383-
try await _signInWithIdToken(credentials: credentials, linkIdentity: false)
384-
}
385-
386-
private func _signInWithIdToken(credentials: OpenIDConnectCredentials, linkIdentity: Bool)
387-
async throws -> Session
388-
{
389-
var credentials = credentials
390-
credentials.linkIdentity = linkIdentity
391-
return try await _signIn(
383+
try await _signIn(
392384
request: .init(
393385
url: configuration.url.appendingPathComponent("token"),
394386
method: .post,
@@ -1193,7 +1185,17 @@ public actor AuthClient {
11931185
public func linkIdentityWithIdToken(
11941186
credentials: OpenIDConnectCredentials
11951187
) async throws -> Session {
1196-
try await _signInWithIdToken(credentials: credentials, linkIdentity: true)
1188+
var credentials = credentials
1189+
credentials.linkIdentity = true
1190+
return try await _signIn(
1191+
request: .init(
1192+
url: configuration.url.appendingPathComponent("token"),
1193+
method: .post,
1194+
query: [URLQueryItem(name: "grant_type", value: "id_token")],
1195+
headers: [.authorization: "Bearer \(session.accessToken)"],
1196+
body: configuration.encoder.encode(credentials)
1197+
)
1198+
)
11971199
}
11981200

11991201
/// Links an OAuth identity to an existing user.

Tests/AuthTests/AuthClientTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ final class AuthClientTests: XCTestCase {
495495
#"""
496496
curl \
497497
--request POST \
498+
--header "Authorization: Bearer accesstoken" \
498499
--header "Content-Length: 166" \
499500
--header "Content-Type: application/json" \
500501
--header "X-Client-Info: auth-swift/0.0.0" \
@@ -508,6 +509,8 @@ final class AuthClientTests: XCTestCase {
508509

509510
let sut = makeSUT()
510511

512+
Dependencies[sut.clientID].sessionStorage.store(.validSession)
513+
511514
try await sut.linkIdentityWithIdToken(
512515
credentials: OpenIDConnectCredentials(
513516
provider: .apple,

0 commit comments

Comments
 (0)