Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
.env
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.0")
],
targets: [
.target(
name: "RxAuthSwift",
dependencies: [
.product(name: "Logging", package: "swift-log"),
.product(name: "Logging", package: "swift-log")
]
),
.target(
Expand Down
40 changes: 40 additions & 0 deletions Sources/RxAuthSwift/AuthenticationState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,44 @@ public struct User: Codable, Identifiable, Sendable, Equatable {
self.email = email
self.image = image
}

enum CodingKeys: String, CodingKey {
case id
case sub
case name
case email
case image
case picture
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
// Support both "id" and "sub" (OIDC standard) for user identifier
if let id = try container.decodeIfPresent(String.self, forKey: .id) {
self.id = id
} else if let sub = try container.decodeIfPresent(String.self, forKey: .sub) {
self.id = sub
Comment on lines +33 to +37
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New decoding behavior supports sub and picture, but current tests only cover round-tripping id and image. Add unit tests that decode JSON payloads containing only sub (no id) and only picture (no image) to ensure this compatibility stays working.

Copilot uses AI. Check for mistakes.
} else {
throw DecodingError.keyNotFound(
CodingKeys.id,
DecodingError.Context(
codingPath: container.codingPath,
debugDescription: "Neither 'id' nor 'sub' found in user info response"
)
)
}
self.name = try container.decodeIfPresent(String.self, forKey: .name)
self.email = try container.decodeIfPresent(String.self, forKey: .email)
// Support both "image" and "picture" (OIDC standard) for profile image
self.image = try container.decodeIfPresent(String.self, forKey: .image)
?? container.decodeIfPresent(String.self, forKey: .picture)
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won’t compile: the second decodeIfPresent call in the nil-coalescing expression is also throwing, but it isn’t prefixed with try (Swift requires try for each throwing call, or try applied to the whole expression). Add try (or restructure) so both decode attempts are handled correctly.

Suggested change
?? container.decodeIfPresent(String.self, forKey: .picture)
?? try container.decodeIfPresent(String.self, forKey: .picture)

Copilot uses AI. Check for mistakes.
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encodeIfPresent(name, forKey: .name)
try container.encodeIfPresent(email, forKey: .email)
try container.encodeIfPresent(image, forKey: .image)
}
}