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

Add support for custom OAuth providers #45

Merged
merged 2 commits into from
Sep 19, 2023
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
2 changes: 1 addition & 1 deletion src/internal/http/DescopeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class DescopeClient: HTTPClient {

func oauthStart(provider: OAuthProvider, redirectURL: String?, refreshJwt: String?, options: LoginOptions?) async throws -> OAuthResponse {
return try await post("auth/oauth/authorize", headers: authorization(with: refreshJwt), params: [
"provider": provider.rawValue,
"provider": provider.name,
"redirectUrl": redirectURL
], body: options?.dictValue ?? [:])
}
Expand Down
10 changes: 8 additions & 2 deletions src/sdk/Callbacks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,17 @@ public extension DescopeOAuth {
///
/// It's recommended to use `ASWebAuthenticationSession` to perform the authentication.
///
/// // use one of the built in constants for the OAuth provider
/// let authURL = try await Descope.oauth.start(provider: .apple, redirectURL: nil)
///
/// // or pass a string with the name of a custom provider
/// let authURL = try await Descope.oauth.start(provider: "myprovider", redirectURL: nil)
///
/// - Important: Make sure a default OAuth redirect URL is configured
/// in the Descope console, or provided by this call.
///
/// - Parameters:
/// - provider: The provider the user wishes to be authenticated by.
/// - provider: The provider the user wishes to authenticate with.
/// - redirectURL: An optional parameter to generate the OAuth link.
/// If not given, the project default will be used.
/// - options: Require additional behaviors when authenticating a user.
Expand Down Expand Up @@ -743,7 +749,7 @@ public extension DescopeSSO {
/// in the Descope console, or provided by this call.
///
/// - Parameters:
/// - provider: The provider the user wishes to be authenticated by.
/// - emailOrTenantName: The user's email address or tenant name.
/// - redirectURL: An optional parameter to generate the SSO link.
/// If not given, the project default will be used.
/// - options: Require additional behaviors when authenticating a user.
Expand Down
10 changes: 8 additions & 2 deletions src/sdk/Routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,17 @@ public protocol DescopeOAuth {
///
/// It's recommended to use `ASWebAuthenticationSession` to perform the authentication.
///
/// // use one of the built in constants for the OAuth provider
/// let authURL = try await Descope.oauth.start(provider: .apple, redirectURL: nil)
///
/// // or pass a string with the name of a custom provider
/// let authURL = try await Descope.oauth.start(provider: "myprovider", redirectURL: nil)
///
/// - Important: Make sure a default OAuth redirect URL is configured
/// in the Descope console, or provided by this call.
///
/// - Parameters:
/// - provider: The provider the user wishes to be authenticated by.
/// - provider: The provider the user wishes to authenticate with.
/// - redirectURL: An optional parameter to generate the OAuth link.
/// If not given, the project default will be used.
/// - options: Require additional behaviors when authenticating a user.
Expand Down Expand Up @@ -462,7 +468,7 @@ public protocol DescopeSSO {
/// in the Descope console, or provided by this call.
///
/// - Parameters:
/// - provider: The provider the user wishes to be authenticated by.
/// - emailOrTenantName: The user's email address or tenant name.
/// - redirectURL: An optional parameter to generate the SSO link.
/// If not given, the project default will be used.
/// - options: Require additional behaviors when authenticating a user.
Expand Down
22 changes: 15 additions & 7 deletions src/types/Others.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ public enum DeliveryMethod: String {
}

/// The provider to use in an OAuth flow.
public enum OAuthProvider: String {
case facebook
case github
case google
case microsoft
case gitlab
case apple
public struct OAuthProvider: ExpressibleByStringLiteral {
public static let facebook: OAuthProvider = "facebook"
public static let github: OAuthProvider = "github"
public static let google: OAuthProvider = "google"
public static let microsoft: OAuthProvider = "microsoft"
public static let gitlab: OAuthProvider = "gitlab"
public static let apple: OAuthProvider = "apple"
public static let slack: OAuthProvider = "slack"
public static let discord: OAuthProvider = "discord"

public let name: String

public init(stringLiteral value: String) {
name = value
}
}

/// Used to provide additional details about a user in sign up calls.
Expand Down