Skip to content

Commit

Permalink
+1
Browse files Browse the repository at this point in the history
  • Loading branch information
borut-t committed Sep 20, 2023
1 parent cffd5f4 commit 5248ba0
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Sources/LinkedIn/LinkedInAuthenticator+Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public extension LinkedInAuthenticator {
let redirectUrl: URL
var authEndpoint: URL = "https://www.linkedin.com/oauth/v2/authorization"
var authCancel: URL = "https://www.linkedin.com/oauth/v2/login-cancel"
var audience: String?
var codeChallenge: String?
var codeChallengeMethod: String?

public init(
clientId: String,
Expand All @@ -35,26 +38,45 @@ public extension LinkedInAuthenticator {
permissions: String,
redirectUrl: URL,
authEndpoint: URL,
authCancel: URL
authCancel: URL,
audience: String?,
codeChallenge: String?,
codeChallengeMethod: String?
) {
self.clientId = clientId
self.clientSecret = clientSecret
self.permissions = permissions
self.redirectUrl = redirectUrl
self.authEndpoint = authEndpoint
self.authCancel = authCancel
self.audience = audience
self.codeChallenge = codeChallenge
self.codeChallengeMethod = codeChallengeMethod
}

func authorizationUrl(state: String) -> URL? {
guard var urlComponents = URLComponents(url: authEndpoint, resolvingAgainstBaseURL: false) else { return nil }
urlComponents.queryItems = [
var queryItems: [URLQueryItem] = [
.init(name: "response_type", value: "code"),
.init(name: "connection", value: "linkedin"),
.init(name: "client_id", value: clientId),
.init(name: "redirect_uri", value: redirectUrl.absoluteString),
.init(name: "state", value: state),
.init(name: "scope", value: permissions)
]

if let audience {
queryItems.append(.init(name: "audience", value: audience))
}
if let codeChallenge {
queryItems.append(.init(name: "code_challenge", value: codeChallenge))
}
if let codeChallengeMethod {
queryItems.append(.init(name: "code_challenge_method", value: codeChallengeMethod))
}

urlComponents.queryItems = queryItems

return urlComponents.url
}
}
Expand Down

0 comments on commit 5248ba0

Please sign in to comment.