Skip to content

Commit

Permalink
Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
borut-t committed Sep 20, 2023
1 parent 759ab22 commit dd37b8a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
28 changes: 25 additions & 3 deletions Sources/LinkedIn/LinkedInAuthenticator+Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,42 @@ public extension LinkedInAuthenticator {
let clientSecret: String
let permissions: String
let redirectUrl: URL
let authEndpoint: URL = "https://www.linkedin.com/oauth/v2/authorization"
let authCancel: URL = "https://www.linkedin.com/oauth/v2/login-cancel"
var authEndpoint: URL = "https://www.linkedin.com/oauth/v2/authorization"
var authCancel: URL = "https://www.linkedin.com/oauth/v2/login-cancel"

public init(clientId: String, clientSecret: String, permissions: String, redirectUrl: URL) {
public init(
clientId: String,
clientSecret: String,
permissions: String,
redirectUrl: URL
) {
self.clientId = clientId
self.clientSecret = clientSecret
self.permissions = permissions
self.redirectUrl = redirectUrl
}

public init(
clientId: String,
clientSecret: String,
permissions: String,
redirectUrl: URL,
authEndpoint: URL,
authCancel: URL
) {
self.clientId = clientId
self.clientSecret = clientSecret
self.permissions = permissions
self.redirectUrl = redirectUrl
self.authEndpoint = authEndpoint
self.authCancel = authCancel
}

func authorizationUrl(state: String) -> URL? {
guard var urlComponents = URLComponents(url: authEndpoint, resolvingAgainstBaseURL: false) else { return nil }
urlComponents.queryItems = [
.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),
Expand Down
18 changes: 9 additions & 9 deletions Sources/LinkedIn/WebView/LinkedInSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import SwiftUI

@available(iOS 15.0, *)
struct LinkedInSheet: ViewModifier {
typealias SuccessHandler = LinkedInWebView.SuccessHandler // (Bool) -> Void
typealias ErrorHandler = LinkedInWebView.ErrorHandler // (Error) -> Void
let config: LinkedInAuthenticator.Configuration
let isPresented: Binding<Bool>
let onSuccess: SuccessHandler?
let onError: ErrorHandler?
public struct LinkedInSheet: ViewModifier {
public typealias SuccessHandler = LinkedInWebView.SuccessHandler // (Bool) -> Void
public typealias ErrorHandler = LinkedInWebView.ErrorHandler // (Error) -> Void
public let config: LinkedInAuthenticator.Configuration
public let isPresented: Binding<Bool>
public let onSuccess: SuccessHandler?
public let onError: ErrorHandler?

func body(content: Content) -> some View {
public func body(content: Content) -> some View {
content
.sheet(isPresented: isPresented) {
LinkedInWebView(with: config) { data in
Expand All @@ -29,7 +29,7 @@ struct LinkedInSheet: ViewModifier {
}

@available(iOS 15.0, *)
extension View {
public extension View {
/// ViewModifier to present `LinkedInWebView` in sheet
func linkedInSheet(with config: LinkedInAuthenticator.Configuration,
isPresented: Binding<Bool>,
Expand Down

0 comments on commit dd37b8a

Please sign in to comment.