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

Release/2.1.0 #35

Merged
merged 4 commits into from
Dec 19, 2024
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
17 changes: 10 additions & 7 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
name: Tests

on:
push:
on:
pull_request:
types: [opened]
types: [opened, synchronize, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
Tests:
runs-on: macos-14-xlarge
runs-on: macos-15-xlarge
steps:
- name: Cancel previous jobs
uses: styfle/[email protected]
Expand All @@ -21,8 +24,8 @@ jobs:
xcode-version: latest-stable

- name: Build project
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild build-for-testing -destination 'name=iPhone 14 Pro' -scheme 'PovioKitAuth-Package' | xcpretty
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild build-for-testing -destination 'name=iPhone 16 Pro,OS=18.0' -scheme 'PovioKitAuth-Package' | xcpretty

- name: Run tests
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild test-without-building -destination 'name=iPhone 14 Pro' -scheme 'PovioKitAuth-Package' | xcpretty
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild test-without-building -destination 'name=iPhone 16 Pro,OS=18.0' -scheme 'PovioKitAuth-Package' | xcpretty

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
.library(name: "PovioKitAuthLinkedIn", targets: ["PovioKitAuthLinkedIn"])
],
dependencies: [
.package(url: "https://github.com/google/GoogleSignIn-iOS", .upToNextMajor(from: "7.0.0")),
.package(url: "https://github.com/google/GoogleSignIn-iOS", .upToNextMajor(from: "8.0.0")),
.package(url: "https://github.com/facebook/facebook-ios-sdk", .upToNextMajor(from: "17.0.0")),
],
targets: [
Expand Down
8 changes: 1 addition & 7 deletions Sources/Apple/AppleAuthenticator+Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ public extension AppleAuthenticator {

/// User full name represented by `givenName` and `familyName`
public var name: String? {
guard let givenName = nameComponents?.givenName else {
return nameComponents?.familyName
}
guard let familyName = nameComponents?.familyName else {
return givenName
}
return "\(givenName) \(familyName)"
nameComponents?.name
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Apple/AppleAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private extension AppleAuthenticator {
}
request.nonce = generateNonceString(length: length).sha256
case .custom(let value):
request.nonce = value
request.nonce = value.sha256
case .none:
break
}
Expand Down
42 changes: 42 additions & 0 deletions Sources/Core/PersonNameComponents+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// PersonNameComponents+Extension.swift
// PovioKitAuth
//
// Created by Egzon Arifi on 09/11/2024.
//

import AuthenticationServices
import Foundation

public extension PersonNameComponents {
var name: String? {
guard let givenName else {
return familyName
}
guard let familyName else {
return givenName
}
return "\(givenName) \(familyName)"
}
}

public extension PersonNameComponents {
init(
namePrefix: String? = .none,
middleName: String? = .none,
givenName: String? = .none,
familyName: String? = .none,
nameSuffix: String? = .none,
nickname: String? = .none,
phoneticRepresentation: PersonNameComponents? = .none
) {
self.init()
self.namePrefix = namePrefix
self.familyName = familyName
self.middleName = middleName
self.givenName = givenName
self.nameSuffix = nameSuffix
self.nickname = nickname
self.phoneticRepresentation = phoneticRepresentation
}
}
15 changes: 6 additions & 9 deletions Sources/Facebook/FacebookAuthenticator+Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ public extension FacebookAuthenticator {
struct Response {
public let userId: String
public let token: String
public let name: String?
public let nameComponents: PersonNameComponents?
public let email: String?
public let expiresAt: Date

/// User full name represented by `givenName` and `familyName`
public var name: String? {
nameComponents?.name
}
}

struct GraphResponse: Decodable {
Expand All @@ -36,11 +41,3 @@ public extension FacebookAuthenticator {
}
}
}

public extension FacebookAuthenticator.GraphResponse {
var displayName: String {
[firstName, lastName]
.compactMap { $0 }
.joined(separator: " ")
}
}
5 changes: 4 additions & 1 deletion Sources/Facebook/FacebookAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ private extension FacebookAuthenticator {
let authResponse = Response(
userId: object.id,
token: token.tokenString,
name: object.displayName,
nameComponents: PersonNameComponents(
givenName: object.firstName,
familyName: object.lastName
),
email: object.email,
expiresAt: token.expirationDate
)
Expand Down
8 changes: 7 additions & 1 deletion Sources/Google/GoogleAuthenticator+Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
//

import Foundation
import PovioKitAuthCore

public extension GoogleAuthenticator {
struct Response {
public let userId: String?
public let idToken: String?
public let accessToken: String
public let refreshToken: String
public let name: String?
public let nameComponents: PersonNameComponents?
public let email: String?
public let expiresAt: Date?

/// User full name represented by `givenName` and `familyName`
public var name: String? {
nameComponents?.name
}
}
}
43 changes: 34 additions & 9 deletions Sources/Google/GoogleAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@ extension GoogleAuthenticator: Authenticator {
/// SignIn user.
///
/// Will asynchronously return the `Response` object on success or `Error` on error.
public func signIn(from presentingViewController: UIViewController,
hint: String? = .none,
additionalScopes: [String]? = .none) async throws -> Response {
public func signIn(
from presentingViewController: UIViewController,
clientId: String? = nil,
hint: String? = .none,
additionalScopes: [String]? = .none
) async throws -> Response {
guard !provider.hasPreviousSignIn() else {
return try await restorePreviousSignIn()
}

return try await signInUser(from: presentingViewController, hint: hint, additionalScopes: additionalScopes)
// set clientId if provided (clientId is needed when doing auth via firebase)
clientId.map { provider.configuration = .init(clientID: $0) }

return try await signInUser(
from: presentingViewController,
hint: hint,
additionalScopes: additionalScopes
)
}

/// Clears the signIn footprint and logs out the user immediatelly.
Expand All @@ -46,7 +56,11 @@ extension GoogleAuthenticator: Authenticator {
/// Boolean if given `url` should be handled.
///
/// Call this from UIApplicationDelegate’s `application:openURL:options:` method.
public func canOpenUrl(_ url: URL, application: UIApplication, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
public func canOpenUrl(
_ url: URL,
application: UIApplication,
options: [UIApplication.OpenURLOptionsKey : Any]
) -> Bool {
GIDSignIn.sharedInstance.handle(url)
}
}
Expand All @@ -66,11 +80,19 @@ private extension GoogleAuthenticator {
}
}
}

func signInUser(from presentingViewController: UIViewController, hint: String?, additionalScopes: [String]?) async throws -> Response {

func signInUser(
from presentingViewController: UIViewController,
hint: String?,
additionalScopes: [String]?
) async throws -> Response {
try await withCheckedThrowingContinuation { continuation in
provider
.signIn(withPresenting: presentingViewController, hint: hint, additionalScopes: additionalScopes) { result, error in
.signIn(
withPresenting: presentingViewController,
hint: hint,
additionalScopes: additionalScopes
) { result, error in
switch (result, error) {
case (let signInResult?, _):
continuation.resume(returning: signInResult.user.authResponse)
Expand Down Expand Up @@ -107,7 +129,10 @@ private extension GIDGoogleUser {
idToken: idToken?.tokenString,
accessToken: accessToken.tokenString,
refreshToken: refreshToken.tokenString,
name: profile?.name,
nameComponents: PersonNameComponents(
givenName: profile?.givenName,
familyName: profile?.familyName
),
email: profile?.email,
expiresAt: accessToken.expirationDate
)
Expand Down
7 changes: 6 additions & 1 deletion Sources/LinkedIn/LinkedInAuthenticator+Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ public extension LinkedInAuthenticator {
struct Response {
public let userId: String
public let token: String
public let name: String
public let nameComponents: PersonNameComponents
public let email: String
public let expiresAt: Date

/// User full name represented by `givenName` and `familyName`
public var name: String? {
nameComponents.name
}
}
}
6 changes: 4 additions & 2 deletions Sources/LinkedIn/LinkedInAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ extension LinkedInAuthenticator: Authenticator {

storage.set(true, forKey: storageIsAuthenticatedKey)

let name = "\(profileResponse.localizedFirstName) \(profileResponse.localizedLastName)"
return Response(
userId: profileResponse.id,
token: authResponse.accessToken,
name: name,
nameComponents: PersonNameComponents(
givenName: profileResponse.localizedFirstName,
familyName: profileResponse.localizedLastName
),
email: emailResponse.emailAddress,
expiresAt: authResponse.expiresIn
)
Expand Down