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

Drop support for Objective-C [SDK-2894] #539

Merged
merged 4 commits into from
Nov 9, 2021
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
9 changes: 4 additions & 5 deletions Auth0.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ web_auth_files = [
'Auth0/OAuth2Grant.swift',
'Auth0/TransactionStore.swift',
'Auth0/WebAuth.swift',
'Auth0/WebAuthError.swift',
'Auth0/_ObjectiveWebAuth.swift'
'Auth0/WebAuthError.swift'
]

ios_files = [
Expand Down Expand Up @@ -67,18 +66,18 @@ Pod::Spec.new do |s|
s.requires_arc = true

s.ios.source_files = 'Auth0/*.{swift,h,m}', 'Auth0/ObjectiveC/*.{h,m}'
s.ios.frameworks = 'UIKit', 'SafariServices', 'LocalAuthentication'
s.ios.weak_framework = 'AuthenticationServices'
s.ios.exclude_files = macos_files
s.ios.frameworks = 'UIKit', 'LocalAuthentication', 'AuthenticationServices'
s.ios.dependency 'SimpleKeychain'
s.ios.dependency 'JWTDecode', '~> 2.0'
s.ios.exclude_files = macos_files
s.ios.pod_target_xcconfig = {
'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => 'WEB_AUTH_PLATFORM',
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) WEB_AUTH_PLATFORM=1'
}

s.osx.source_files = 'Auth0/*.{swift,h,m}', 'Auth0/ObjectiveC/*.{h,m}'
s.osx.exclude_files = ios_files
s.osx.frameworks = 'AppKit', 'LocalAuthentication', 'AuthenticationServices'
s.osx.dependency 'SimpleKeychain'
s.osx.dependency 'JWTDecode', '~> 2.0'
s.osx.pod_target_xcconfig = {
Expand Down
73 changes: 0 additions & 73 deletions Auth0.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

39 changes: 17 additions & 22 deletions Auth0/Credentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,31 @@ import Foundation

/**
User's credentials obtained from Auth0.
What values are available depends on what type of Auth request you perfomed,
so if you used WebAuth (`/authorize` call) the `response_type` and `scope` will determine what tokens you get
*/
@objc(A0Credentials)
public class Credentials: NSObject, JSONObjectPayload, NSSecureCoding {

/// Token used that allows calling to the requested APIs (audience sent on Auth)
@objc public let accessToken: String
public let accessToken: String
/// Type of the access token
@objc public let tokenType: String
public let tokenType: String
/// When the access_token expires
@objc public let expiresIn: Date
public let expiresIn: Date
/// If the API allows you to request new access tokens and the scope `offline_access` was included on Auth
@objc public let refreshToken: String?
public let refreshToken: String?
/// Token that details the user identity after authentication
@objc public let idToken: String
public let idToken: String
/// Granted scopes, only populated when a requested scope or scopes was not granted and Auth is OIDC Conformant
@objc public let scope: String?
public let scope: String?
/// MFA recovery code that the application must display to the end-user to be stored securely for future use
@objc public let recoveryCode: String?
public let recoveryCode: String?

@objc public init(accessToken: String = "",
tokenType: String = "",
idToken: String = "",
refreshToken: String? = nil,
expiresIn: Date = Date(),
scope: String? = nil,
recoveryCode: String? = nil) {
public init(accessToken: String = "",
tokenType: String = "",
idToken: String = "",
refreshToken: String? = nil,
expiresIn: Date = Date(),
scope: String? = nil,
recoveryCode: String? = nil) {
self.accessToken = accessToken
self.tokenType = tokenType
self.idToken = idToken
Expand All @@ -42,11 +39,9 @@ public class Credentials: NSObject, JSONObjectPayload, NSSecureCoding {
convenience required public init(json: [String: Any]) {
var expiresIn: Date?

if let value = json["expires_in"] {
let string = String(describing: value)
if let double = NumberFormatter().number(from: string)?.doubleValue {
expiresIn = Date(timeIntervalSinceNow: double)
}
if let value = json["expires_in"],
let double = NumberFormatter().number(from: String(describing: value))?.doubleValue {
expiresIn = Date(timeIntervalSinceNow: double)
}

self.init(accessToken: json["access_token"] as? String ?? "",
Expand Down
3 changes: 1 addition & 2 deletions Auth0/CredentialsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public struct CredentialsManager {
/// - Returns: if there are valid and non-expired credentials stored.
public func hasValid(minTTL: Int = 0) -> Bool {
guard let data = self.storage.data(forKey: self.storeKey),
let credentials = NSKeyedUnarchiver.unarchiveObject(with: data) as? Credentials,
credentials.accessToken != nil else { return false }
let credentials = NSKeyedUnarchiver.unarchiveObject(with: data) as? Credentials else { return false }
return (!self.hasExpired(credentials) && !self.willExpire(credentials, within: minTTL)) || credentials.refreshToken != nil
}

Expand Down
16 changes: 0 additions & 16 deletions Auth0/DesktopWebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ public func resumeAuth(_ urls: [URL]) {
_ = TransactionStore.shared.resume(url)
}

public extension _ObjectiveOAuth2 {

/**
Resumes the current Auth session (if any).

- parameter urls: urls received by the macOS application in AppDelegate
- warning: deprecated as the SDK will not support macOS versions older than Catalina
*/
@available(*, deprecated, message: "the SDK will not support macOS versions older than Catalina")
@objc(resumeAuthWithURLs:)
static func resume(_ urls: [URL]) {
resumeAuth(urls)
}

}

extension ASTransaction: ASWebAuthenticationPresentationContextProviding {

func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
Expand Down
18 changes: 0 additions & 18 deletions Auth0/MobileWebAuth.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#if os(iOS)
import UIKit
import SafariServices
import AuthenticationServices

public typealias A0URLOptionsKey = UIApplication.OpenURLOptionsKey
Expand All @@ -18,23 +17,6 @@ public func resumeAuth(_ url: URL, options: [A0URLOptionsKey: Any] = [:]) -> Boo
return TransactionStore.shared.resume(url)
}

public extension _ObjectiveOAuth2 {

/**
Resumes the current Auth session (if any).

- parameter url: url received by iOS application in AppDelegate
- parameter options: dictionary with launch options received by iOS application in AppDelegate

- returns: if the url was handled by an on going session or not.
*/
@objc(resumeAuthWithURL:options:)
static func resume(_ url: URL, options: [A0URLOptionsKey: Any]) -> Bool {
return resumeAuth(url)
}

}

@available(iOS 13.0, *)
extension ASTransaction: ASWebAuthenticationPresentationContextProviding {

Expand Down
2 changes: 1 addition & 1 deletion Auth0/NSApplication+Shared.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#if os(macOS)
import Cocoa
import AppKit

extension NSApplication {

Expand Down
6 changes: 0 additions & 6 deletions Auth0/NSError+Helper.swift

This file was deleted.

77 changes: 69 additions & 8 deletions Auth0/UserInfo.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
import Foundation

/// OIDC Standard Claims user information
/// - note: [Claims](https://auth0.com/docs/protocols/oidc#claims)
@objc(A0UserInfo)
@objcMembers public class UserInfo: NSObject, JSONObjectPayload {

public static let publicClaims = ["sub", "name", "given_name", "family_name", "middle_name", "nickname", "preferred_username", "profile", "picture", "website", "email", "email_verified", "gender", "birthdate", "zoneinfo", "locale", "phone_number", "phone_number_verified", "address", "updated_at"]
/// - note: [Claims](https://auth0.com/docs/security/tokens/json-web-tokens/json-web-token-claims)
public struct UserInfo: JSONObjectPayload {

public static let publicClaims = [
"sub",
"name",
"given_name",
"family_name",
"middle_name",
"nickname",
"preferred_username",
"profile",
"picture",
"website",
"email",
"email_verified",
"gender",
"birthdate",
"zoneinfo",
"locale",
"phone_number",
"phone_number_verified",
"address",
"updated_at"
]

public let sub: String

Expand Down Expand Up @@ -37,7 +57,27 @@ import Foundation

public let customClaims: [String: Any]?

required public init(sub: String, name: String?, givenName: String?, familyName: String?, middleName: String?, nickname: String?, preferredUsername: String?, profile: URL?, picture: URL?, website: URL?, email: String?, emailVerified: Bool?, gender: String?, birthdate: String?, zoneinfo: TimeZone?, locale: Locale?, phoneNumber: String?, phoneNumberVerified: Bool?, address: [String: String]?, updatedAt: Date?, customClaims: [String: Any]?) {
public init(sub: String,
name: String?,
givenName: String?,
familyName: String?,
middleName: String?,
nickname: String?,
preferredUsername: String?,
profile: URL?,
picture: URL?,
website: URL?,
email: String?,
emailVerified: Bool?,
gender: String?,
birthdate: String?,
zoneinfo: TimeZone?,
locale: Locale?,
phoneNumber: String?,
phoneNumberVerified: Bool?,
address: [String: String]?,
updatedAt: Date?,
customClaims: [String: Any]?) {
self.sub = sub

self.name = name
Expand Down Expand Up @@ -69,7 +109,8 @@ import Foundation
self.customClaims = customClaims
}

convenience required public init?(json: [String: Any]) {
// swiftlint:disable:next type_body_length
public init?(json: [String: Any]) {
guard let sub = json["sub"] as? String else { return nil }

let name = json["name"] as? String
Expand Down Expand Up @@ -112,6 +153,26 @@ import Foundation
var customClaims = json
UserInfo.publicClaims.forEach { customClaims.removeValue(forKey: $0) }

self.init(sub: sub, name: name, givenName: givenName, familyName: familyName, middleName: middleName, nickname: nickname, preferredUsername: preferredUsername, profile: profile, picture: picture, website: website, email: email, emailVerified: emailVerified, gender: gender, birthdate: birthdate, zoneinfo: zoneinfo, locale: locale, phoneNumber: phoneNumber, phoneNumberVerified: phoneNumberVerified, address: address, updatedAt: updatedAt, customClaims: customClaims)
self.init(sub: sub,
name: name,
givenName: givenName,
familyName: familyName,
middleName: middleName,
nickname: nickname,
preferredUsername: preferredUsername,
profile: profile,
picture: picture,
website: website,
email: email,
emailVerified: emailVerified,
gender: gender,
birthdate: birthdate,
zoneinfo: zoneinfo,
locale: locale,
phoneNumber: phoneNumber,
phoneNumberVerified: phoneNumberVerified,
address: address,
updatedAt: updatedAt,
customClaims: customClaims)
}
}
Loading