Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added requestUsingIDToken configuration #406

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions Sources/Base/OAuth2AuthConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public struct OAuth2AuthConfig {
/// - macOS: An NSWindow from which to present a modal sheet _or_ `nil` to present in a new window
public weak var authorizeContext: AnyObject? = nil

/// Whether to use the `id_token` instead of the `access_token` for signed requests
public var requestUsingIDToken = false

/// UI-specific configuration.
public var ui = UI()
}
Expand Down
13 changes: 10 additions & 3 deletions Sources/Base/extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ extension URLRequest {
- parameter oauth2: The OAuth2 instance providing the access token to sign the request
*/
public mutating func sign(with oauth2: OAuth2Base) throws {
guard let access = oauth2.clientConfig.accessToken, !access.isEmpty else {
throw OAuth2Error.noAccessToken
if oauth2.authConfig.requestUsingIDToken {
guard let idToken = oauth2.clientConfig.idToken, !idToken.isEmpty else {
throw OAuth2Error.noAccessToken
}
setValue("Bearer \(idToken)", forHTTPHeaderField: "Authorization")
} else {
guard let access = oauth2.clientConfig.accessToken, !access.isEmpty else {
throw OAuth2Error.noAccessToken
}
setValue("Bearer \(access)", forHTTPHeaderField: "Authorization")
}
setValue("Bearer \(access)", forHTTPHeaderField: "Authorization")
}

/**
Expand Down