Skip to content

Commit 38c6bc3

Browse files
authored
Enable Credentials Manager for tvOS and Mac Platforms (#206)
* Enable Credentials Manager for tvOS,Mac Platforms Restrict BioMetrics for iOS Platform Only Added tvOS, Mac Apps for Hosted Testing (Required for Keychain) * CI Build SimpleKeyhain for all platforms * Add SimpleKeychain CocoaPod dependency to tvOS, Mac * Fix WatchOS Exclusion
1 parent 7edaf75 commit 38c6bc3

File tree

39 files changed

+1823
-16
lines changed

39 files changed

+1823
-16
lines changed

Auth0.podspec

+24-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,30 @@ web_auth_files = [
1616
'Auth0/SilentSafariViewController.swift',
1717
'Auth0/NativeAuth.swift',
1818
'Auth0/AuthProvider.swift',
19-
'Auth0/CredentialsManager.swift',
20-
'Auth0/CredentialsManagerError.swift',
2119
'Auth0/BioAuthentication.swift'
2220
]
2321

22+
watchos_exclude_files = [
23+
'Auth0/_ObjectiveWebAuth.swift',
24+
'Auth0/ControllerModalPresenter.swift',
25+
'Auth0/OAuth2Grant.swift',
26+
'Auth0/AuthTransaction.swift',
27+
'Auth0/TransactionStore.swift',
28+
'Auth0/WebAuth.swift',
29+
'Auth0/WebAuthError.swift',
30+
'Auth0/SafariWebAuth.swift',
31+
'Auth0/AuthSession.swift',
32+
'Auth0/SafariSession.swift',
33+
'Auth0/SafariAuthenticationSession.swift',
34+
'Auth0/SafariAuthenticationCallback.swift',
35+
'Auth0/SilentSafariViewController.swift',
36+
'Auth0/NativeAuth.swift',
37+
'Auth0/AuthProvider.swift',
38+
'Auth0/BioAuthentication.swift',
39+
'Auth0/CredentialsManagerError.swift',
40+
'Auth0/CredentialsManager.swift'
41+
]
42+
2443
Pod::Spec.new do |s|
2544
s.name = 'Auth0'
2645
s.version = version
@@ -45,8 +64,10 @@ Pod::Spec.new do |s|
4564
s.ios.dependency 'SimpleKeychain'
4665
s.osx.source_files = 'Auth0/*.swift'
4766
s.osx.exclude_files = web_auth_files
67+
s.osx.dependency 'SimpleKeychain'
4868
s.watchos.source_files = 'Auth0/*.swift'
49-
s.watchos.exclude_files = web_auth_files
69+
s.watchos.exclude_files = watchos_exclude_files
5070
s.tvos.source_files = 'Auth0/*.swift'
5171
s.tvos.exclude_files = web_auth_files
72+
s.tvos.dependency 'SimpleKeychain'
5273
end

Auth0.xcodeproj/project.pbxproj

+504-4
Large diffs are not rendered by default.

Auth0.xcodeproj/xcshareddata/xcschemes/Auth0.iOS.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0930"
3+
LastUpgradeVersion = "0940"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Auth0.xcodeproj/xcshareddata/xcschemes/Auth0.macOS.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0930"
3+
LastUpgradeVersion = "0940"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Auth0.xcodeproj/xcshareddata/xcschemes/Auth0.tvOS.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0930"
3+
LastUpgradeVersion = "0940"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Auth0/Auth0Authentication.swift

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct Auth0Authentication: Authentication {
5454
return Request(session: session, url: resourceOwner, method: "POST", handle: authenticationObject, payload: payload, logger: self.logger, telemetry: self.telemetry)
5555
}
5656

57+
// swiftlint:disable:next function_parameter_count
5758
func login(usernameOrEmail username: String, password: String, realm: String, audience: String?, scope: String?, parameters: [String: Any]?) -> Request<Credentials, AuthenticationError> {
5859
let resourceOwner = URL(string: "/oauth/token", relativeTo: self.url)!
5960
var payload: [String: Any] = [

Auth0/CredentialsManager.swift

+20-5
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@
2222

2323
import Foundation
2424
import SimpleKeychain
25+
#if os(iOS)
2526
import LocalAuthentication
27+
#endif
2628

2729
/// Credentials management utility
2830
public struct CredentialsManager {
2931

3032
private let storage = A0SimpleKeychain()
3133
private let storeKey = "credentials"
3234
private let authentication: Authentication
35+
#if os(iOS)
3336
private var bioAuth: BioAuthentication?
37+
#endif
3438

3539
/// Creates a new CredentialsManager instance
3640
///
@@ -46,20 +50,24 @@ public struct CredentialsManager {
4650
/// - title: main message to display in TouchID prompt
4751
/// - cancelTitle: cancel message to display in TouchID prompt (iOS 10+)
4852
/// - fallbackTitle: fallback message to display in TouchID prompt after a failed match
53+
#if os(iOS)
4954
@available(*, deprecated, message: "see enableBiometrics(withTitle title:, cancelTitle:, fallbackTitle:)")
5055
public mutating func enableTouchAuth(withTitle title: String, cancelTitle: String? = nil, fallbackTitle: String? = nil) {
5156
self.enableBiometrics(withTitle: title, cancelTitle: cancelTitle, fallbackTitle: fallbackTitle)
5257
}
58+
#endif
5359

5460
/// Enable Biometric Authentication for additional securtity during credentials retrieval.
5561
///
5662
/// - Parameters:
5763
/// - title: main message to display when Touch ID is used
5864
/// - cancelTitle: cancel message to display when Touch ID is used (iOS 10+)
5965
/// - fallbackTitle: fallback message to display when Touch ID is used after a failed match
66+
#if os(iOS)
6067
public mutating func enableBiometrics(withTitle title: String, cancelTitle: String? = nil, fallbackTitle: String? = nil) {
6168
self.bioAuth = BioAuthentication(authContext: LAContext(), title: title, cancelTitle: cancelTitle, fallbackTitle: fallbackTitle)
6269
}
70+
#endif
6371

6472
/// Store credentials instance in keychain
6573
///
@@ -106,6 +114,7 @@ public struct CredentialsManager {
106114
/// - callback: callback with the user's credentials or the cause of the error.
107115
/// - Important: This method only works for a refresh token obtained after auth with OAuth 2.0 API Authorization.
108116
/// - Note: [Auth0 Refresh Tokens Docs](https://auth0.com/docs/tokens/refresh-token)
117+
#if os(iOS)
109118
public func credentials(withScope scope: String? = nil, callback: @escaping (CredentialsManagerError?, Credentials?) -> Void) {
110119
guard self.hasValid() else { return callback(.noCredentials, nil) }
111120
if let bioAuth = self.bioAuth {
@@ -120,6 +129,12 @@ public struct CredentialsManager {
120129
self.retrieveCredentials(withScope: scope, callback: callback)
121130
}
122131
}
132+
#else
133+
public func credentials(withScope scope: String? = nil, callback: @escaping (CredentialsManagerError?, Credentials?) -> Void) {
134+
guard self.hasValid() else { return callback(.noCredentials, nil) }
135+
self.retrieveCredentials(withScope: scope, callback: callback)
136+
}
137+
#endif
123138

124139
private func retrieveCredentials(withScope scope: String? = nil, callback: @escaping (CredentialsManagerError?, Credentials?) -> Void) {
125140
guard
@@ -134,11 +149,11 @@ public struct CredentialsManager {
134149
switch $0 {
135150
case .success(let credentials):
136151
let newCredentials = Credentials(accessToken: credentials.accessToken,
137-
tokenType: credentials.tokenType,
138-
idToken: credentials.idToken,
139-
refreshToken: refreshToken,
140-
expiresIn: credentials.expiresIn,
141-
scope: credentials.scope)
152+
tokenType: credentials.tokenType,
153+
idToken: credentials.idToken,
154+
refreshToken: refreshToken,
155+
expiresIn: credentials.expiresIn,
156+
scope: credentials.scope)
142157
_ = self.store(credentials: newCredentials)
143158
callback(nil, newCredentials)
144159
case .failure(let error):

Auth0Tests/CredentialsManagerSpec.swift

+4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import Quick
2424
import Nimble
2525
import OHHTTPStubs
2626
import SimpleKeychain
27+
#if os(iOS)
2728
import LocalAuthentication
29+
#endif
2830

2931
@testable import Auth0
3032

@@ -157,6 +159,7 @@ class CredentialsManagerSpec: QuickSpec {
157159
expect(newCredentials).toEventuallyNot(beNil())
158160
}
159161

162+
#if os(iOS)
160163
context("require touch") {
161164

162165
beforeEach {
@@ -176,6 +179,7 @@ class CredentialsManagerSpec: QuickSpec {
176179
}
177180
}
178181
}
182+
#endif
179183

180184
context("renew") {
181185

OAuth2Mac/AppDelegate.swift

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// AppDelegate.swift
3+
// OAuth2Mac
4+
//
5+
// Created by Martin on 16/07/2018.
6+
// Copyright © 2018 Auth0. All rights reserved.
7+
//
8+
9+
import Cocoa
10+
11+
@NSApplicationMain
12+
class AppDelegate: NSObject, NSApplicationDelegate {
13+
14+
15+
16+
func applicationDidFinishLaunching(_ aNotification: Notification) {
17+
// Insert code here to initialize your application
18+
}
19+
20+
func applicationWillTerminate(_ aNotification: Notification) {
21+
// Insert code here to tear down your application
22+
}
23+
24+
25+
}
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "mac",
5+
"size" : "16x16",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "mac",
10+
"size" : "16x16",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "mac",
15+
"size" : "32x32",
16+
"scale" : "1x"
17+
},
18+
{
19+
"idiom" : "mac",
20+
"size" : "32x32",
21+
"scale" : "2x"
22+
},
23+
{
24+
"idiom" : "mac",
25+
"size" : "128x128",
26+
"scale" : "1x"
27+
},
28+
{
29+
"idiom" : "mac",
30+
"size" : "128x128",
31+
"scale" : "2x"
32+
},
33+
{
34+
"idiom" : "mac",
35+
"size" : "256x256",
36+
"scale" : "1x"
37+
},
38+
{
39+
"idiom" : "mac",
40+
"size" : "256x256",
41+
"scale" : "2x"
42+
},
43+
{
44+
"idiom" : "mac",
45+
"size" : "512x512",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "mac",
50+
"size" : "512x512",
51+
"scale" : "2x"
52+
}
53+
],
54+
"info" : {
55+
"version" : 1,
56+
"author" : "xcode"
57+
}
58+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}

0 commit comments

Comments
 (0)