Skip to content

Commit 7757181

Browse files
authoredSep 9, 2016
Merge pull request #43 from auth0/feature-rework-logging
Rework Logging
2 parents 7aaabdf + 235207d commit 7757181

16 files changed

+311
-77
lines changed
 

‎App/AppDelegate.swift

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2929
var window: UIWindow?
3030

3131
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
32-
Auth0.enableLogging()
3332
return true
3433
}
3534

‎App/ViewController.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ class ViewController: UIViewController {
3333
}
3434

3535
@IBAction func startOAuth2(sender: AnyObject) {
36-
Auth0.webAuth().start(onAuth)
36+
var auth0 = Auth0.webAuth()
37+
auth0
38+
.logging(enabled: true)
39+
.start(onAuth)
3740
}
3841

3942
@IBAction func startGoogleOAuth2(sender: AnyObject) {
40-
Auth0.webAuth().connection("google-oauth2").start(onAuth)
43+
var auth0 = Auth0.webAuth()
44+
auth0
45+
.logging(enabled: true)
46+
.connection("google-oauth2")
47+
.start(onAuth)
4148
}
4249
}

‎Auth0.xcodeproj/project.pbxproj

+27-6
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@
6868
5F23E7131D4B890500C3F2D9 /* A0ChallengeGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 5FC34AF61D0101BF000F28F5 /* A0ChallengeGenerator.m */; };
6969
5F23E71A1D4B891E00C3F2D9 /* Auth0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F06DDC81CC66B710011842B /* Auth0.swift */; };
7070
5F23E71B1D4B891E00C3F2D9 /* Auth0Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FD255B61D14F00900387ECB /* Auth0Error.swift */; };
71-
5F2BD4041D09F7B700B5F7D2 /* _ObjectiveLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F2BD4031D09F7B700B5F7D2 /* _ObjectiveLogger.swift */; };
72-
5F2BD4051D09F7B700B5F7D2 /* _ObjectiveLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F2BD4031D09F7B700B5F7D2 /* _ObjectiveLogger.swift */; };
71+
5F28B4611D8216180000EB23 /* Loggable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F28B4601D8216180000EB23 /* Loggable.swift */; };
72+
5F28B4621D8216180000EB23 /* Loggable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F28B4601D8216180000EB23 /* Loggable.swift */; };
73+
5F28B4631D8216180000EB23 /* Loggable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F28B4601D8216180000EB23 /* Loggable.swift */; };
74+
5F28B4641D8216180000EB23 /* Loggable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F28B4601D8216180000EB23 /* Loggable.swift */; };
75+
5F28B4671D8300D50000EB23 /* LoggerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F28B4661D8300D50000EB23 /* LoggerSpec.swift */; };
76+
5F28B4681D8300D50000EB23 /* LoggerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F28B4661D8300D50000EB23 /* LoggerSpec.swift */; };
77+
5F28B4691D8300D50000EB23 /* LoggerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F28B4661D8300D50000EB23 /* LoggerSpec.swift */; };
7378
5F331AFE1D4BB24C00AE4382 /* Auth0.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F23E6F61D4B87F000C3F2D9 /* Auth0.framework */; };
7479
5F331B041D4BB78C00AE4382 /* TelemetrySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FE686A91D1894AA0075874C /* TelemetrySpec.swift */; };
7580
5F331B051D4BB7D400AE4382 /* AuthenticationSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FBBF0421CCA90300024D2AF /* AuthenticationSpec.swift */; };
@@ -298,7 +303,8 @@
298303
5F23E6B91D4ACA7100C3F2D9 /* Auth0.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Auth0.framework; sourceTree = BUILT_PRODUCTS_DIR; };
299304
5F23E6F61D4B87F000C3F2D9 /* Auth0.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Auth0.framework; sourceTree = BUILT_PRODUCTS_DIR; };
300305
5F23E6FA1D4B87F000C3F2D9 /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Info-tvOS.plist"; path = "Auth0/Info-tvOS.plist"; sourceTree = SOURCE_ROOT; };
301-
5F2BD4031D09F7B700B5F7D2 /* _ObjectiveLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _ObjectiveLogger.swift; sourceTree = "<group>"; };
306+
5F28B4601D8216180000EB23 /* Loggable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Loggable.swift; sourceTree = "<group>"; };
307+
5F28B4661D8300D50000EB23 /* LoggerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoggerSpec.swift; sourceTree = "<group>"; };
302308
5F331AF91D4BB24C00AE4382 /* Auth0Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Auth0Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
303309
5F331B121D4BCBD400AE4382 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/tvOS/Quick.framework; sourceTree = "<group>"; };
304310
5F331B131D4BCBD400AE4382 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/tvOS/Nimble.framework; sourceTree = "<group>"; };
@@ -492,6 +498,7 @@
492498
5F06DD921CC451430011842B /* Auth0Tests */ = {
493499
isa = PBXGroup;
494500
children = (
501+
5F28B4651D8300BB0000EB23 /* Logger */,
495502
5FE686A81D1894990075874C /* Telemetry */,
496503
5FBBF0411CCA901B0024D2AF /* Authentication */,
497504
5FADB6011CEC0C1600D4BB50 /* Management */,
@@ -538,6 +545,14 @@
538545
name = OSX;
539546
sourceTree = "<group>";
540547
};
548+
5F28B4651D8300BB0000EB23 /* Logger */ = {
549+
isa = PBXGroup;
550+
children = (
551+
5F28B4661D8300D50000EB23 /* LoggerSpec.swift */,
552+
);
553+
name = Logger;
554+
sourceTree = "<group>";
555+
};
541556
5F331B111D4BB8D700AE4382 /* tvOS */ = {
542557
isa = PBXGroup;
543558
children = (
@@ -579,7 +594,7 @@
579594
isa = PBXGroup;
580595
children = (
581596
5F6FAC621D09E98000D5B4EA /* Logger.swift */,
582-
5F2BD4031D09F7B700B5F7D2 /* _ObjectiveLogger.swift */,
597+
5F28B4601D8216180000EB23 /* Loggable.swift */,
583598
);
584599
path = Logger;
585600
sourceTree = "<group>";
@@ -1091,6 +1106,7 @@
10911106
5FCCC31C1CF51DF300901E2E /* _ObjectiveManagementAPI.swift in Sources */,
10921107
5FC34AF81D0101BF000F28F5 /* A0ChallengeGenerator.m in Sources */,
10931108
5F6FAC631D09E98000D5B4EA /* Logger.swift in Sources */,
1109+
5F28B4611D8216180000EB23 /* Loggable.swift in Sources */,
10941110
5FBBF0461CCA99E90024D2AF /* Credentials.swift in Sources */,
10951111
5F53F5CE1CFD157300476A46 /* OAuth2Session.swift in Sources */,
10961112
5FBEF3DC1D079F2100D90941 /* _ObjectiveWebAuth.swift in Sources */,
@@ -1102,7 +1118,6 @@
11021118
5FD255BA1D14F70B00387ECB /* WebAuthError.swift in Sources */,
11031119
5FD255B71D14F00900387ECB /* Auth0Error.swift in Sources */,
11041120
5FD255AE1D14A4A300387ECB /* AuthenticationError.swift in Sources */,
1105-
5F2BD4041D09F7B700B5F7D2 /* _ObjectiveLogger.swift in Sources */,
11061121
5F06DDC91CC66B710011842B /* Auth0.swift in Sources */,
11071122
5FE2F8B21CCEAED8003628F4 /* Requestable.swift in Sources */,
11081123
5FCCC3191CF51BBD00901E2E /* NSError+Management.swift in Sources */,
@@ -1129,6 +1144,7 @@
11291144
files = (
11301145
5FE2F8BC1CD0EAAD003628F4 /* Response.swift in Sources */,
11311146
5FCCC31D1CF51DF300901E2E /* _ObjectiveManagementAPI.swift in Sources */,
1147+
5F28B4621D8216180000EB23 /* Loggable.swift in Sources */,
11321148
5FBBF0471CCA99E90024D2AF /* Credentials.swift in Sources */,
11331149
5F74CB3E1CEE8E9100226823 /* Identity.swift in Sources */,
11341150
5F6FAC641D09E98000D5B4EA /* Logger.swift in Sources */,
@@ -1144,7 +1160,6 @@
11441160
5FADB60D1CED7E0800D4BB50 /* UserPatchAttributes.swift in Sources */,
11451161
5F7989521CF13A20009E8A10 /* _ObjectiveAuthenticationAPI.swift in Sources */,
11461162
5F74CB411CEFD5E600226823 /* JSONObjectPayload.swift in Sources */,
1147-
5F2BD4051D09F7B700B5F7D2 /* _ObjectiveLogger.swift in Sources */,
11481163
5FD255AF1D14A4A300387ECB /* AuthenticationError.swift in Sources */,
11491164
5FE2F8B91CD0E910003628F4 /* Request.swift in Sources */,
11501165
5FE2F8AA1CCE54F1003628F4 /* Result.swift in Sources */,
@@ -1173,6 +1188,7 @@
11731188
5FE2F8A61CCA9C17003628F4 /* CredentialsSpec.swift in Sources */,
11741189
5FADB6091CED500900D4BB50 /* ManagementSpec.swift in Sources */,
11751190
5FCAB16D1D07AC3500331C84 /* WebAuthSpec.swift in Sources */,
1191+
5F28B4671D8300D50000EB23 /* LoggerSpec.swift in Sources */,
11761192
5FBBF0431CCA90300024D2AF /* AuthenticationSpec.swift in Sources */,
11771193
5FCAB16B1D07AC3500331C84 /* OAuth2GrantSpec.swift in Sources */,
11781194
5FD255B11D14A9E000387ECB /* AuthenticationErrorSpec.swift in Sources */,
@@ -1198,6 +1214,7 @@
11981214
5FE2F8A71CCA9C17003628F4 /* CredentialsSpec.swift in Sources */,
11991215
5FD255B21D14A9E000387ECB /* AuthenticationErrorSpec.swift in Sources */,
12001216
5FADB60A1CED500900D4BB50 /* ManagementSpec.swift in Sources */,
1217+
5F28B4681D8300D50000EB23 /* LoggerSpec.swift in Sources */,
12011218
5FBBF0441CCA90300024D2AF /* AuthenticationSpec.swift in Sources */,
12021219
5FE2F8C71CD1522F003628F4 /* ProfileSpec.swift in Sources */,
12031220
5FE2F8BF1CD0EC52003628F4 /* ResponseSpec.swift in Sources */,
@@ -1219,6 +1236,7 @@
12191236
5F23E6DD1D4ACD6100C3F2D9 /* NSURL+Auth0.swift in Sources */,
12201237
5F23E6D71D4ACD5B00C3F2D9 /* Credentials.swift in Sources */,
12211238
5F23E6E71D4ACD8500C3F2D9 /* Response.swift in Sources */,
1239+
5F28B4631D8216180000EB23 /* Loggable.swift in Sources */,
12221240
5F23E6E01D4ACD7F00C3F2D9 /* Management.swift in Sources */,
12231241
5F23E6DA1D4ACD5B00C3F2D9 /* Profile.swift in Sources */,
12241242
5F23E6D51D4ACD4C00C3F2D9 /* Telemetry.swift in Sources */,
@@ -1248,6 +1266,7 @@
12481266
5F23E7011D4B88DB00C3F2D9 /* Credentials.swift in Sources */,
12491267
5F23E71A1D4B891E00C3F2D9 /* Auth0.swift in Sources */,
12501268
5F23E7101D4B88FC00C3F2D9 /* Response.swift in Sources */,
1269+
5F28B4641D8216180000EB23 /* Loggable.swift in Sources */,
12511270
5F23E7091D4B88F600C3F2D9 /* Management.swift in Sources */,
12521271
5F23E7041D4B88DB00C3F2D9 /* Profile.swift in Sources */,
12531272
5F23E6FF1D4B88D400C3F2D9 /* Telemetry.swift in Sources */,
@@ -1273,6 +1292,7 @@
12731292
5F331B061D4BB7DA00AE4382 /* CredentialsSpec.swift in Sources */,
12741293
5F331B0B1D4BB7F900AE4382 /* UserPatchAttributesSpec.swift in Sources */,
12751294
5F331B051D4BB7D400AE4382 /* AuthenticationSpec.swift in Sources */,
1295+
5F28B4691D8300D50000EB23 /* LoggerSpec.swift in Sources */,
12761296
5F331B0C1D4BB7F900AE4382 /* UsersSpec.swift in Sources */,
12771297
5F331B0E1D4BB80700AE4382 /* Matchers.swift in Sources */,
12781298
5F331B071D4BB7E300AE4382 /* IdentitySpec.swift in Sources */,
@@ -1869,6 +1889,7 @@
18691889
5F331B021D4BB24C00AE4382 /* Release */,
18701890
);
18711891
defaultConfigurationIsVisible = 0;
1892+
defaultConfigurationName = Release;
18721893
};
18731894
5F3965E11CF67DD800CDE7C0 /* Build configuration list for PBXNativeTarget "OAuth2" */ = {
18741895
isa = XCConfigurationList;

‎Auth0/Auth0.swift

-11
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,6 @@ public func users(token token: String, domain: String, session: NSURLSession = .
190190
return management(token: token, domain: domain, session: session).users()
191191
}
192192

193-
/**
194-
Turn on/off Auth0.swift debug logging of HTTP requests and OAuth2 flow (iOS only).
195-
196-
- parameter enabled: optional flag to turn on/off logging
197-
- note: By default all logging is **disabled**
198-
- important: Logging should be turned on/off **before** making request to Auth0 for the flag to take effect.
199-
*/
200-
public func enableLogging(enabled enabled: Bool = true) {
201-
Auth0Logger.sharedInstance.logger = enabled ? DefaultLogger() : nil
202-
}
203-
204193
func plistValues(bundle bundle: NSBundle) -> (clientId: String, domain: String)? {
205194
guard
206195
let path = bundle.pathForResource("Auth0", ofType: "plist"),

‎Auth0/Authentication/Authentication.swift

+11-10
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ public typealias DatabaseUser = (email: String, username: String?, verified: Boo
2828
Auth endpoints of Auth0
2929
- seeAlso: [Auth0 Auth API docs](https://auth0.com/docs/api/authentication)
3030
*/
31-
public struct Authentication: Trackable {
31+
public struct Authentication: Trackable, Loggable {
3232
public let clientId: String
3333
public let url: NSURL
3434
public var telemetry: Telemetry
35+
public var logger: Logger?
3536

3637
let session: NSURLSession
3738

@@ -103,7 +104,7 @@ public struct Authentication: Trackable {
103104
]
104105
payload["mfa_code"] = multifactorCode
105106
parameters.forEach { key, value in payload[key] = value }
106-
return Request(session: session, url: resourceOwner, method: "POST", handle: authenticationObject, payload: payload, telemetry: self.telemetry)
107+
return Request(session: session, url: resourceOwner, method: "POST", handle: authenticationObject, payload: payload, logger: self.logger, telemetry: self.telemetry)
107108
}
108109

109110

@@ -154,7 +155,7 @@ public struct Authentication: Trackable {
154155
payload["user_metadata"] = userMetadata
155156

156157
let createUser = NSURL(string: "/dbconnections/signup", relativeToURL: self.url)!
157-
return Request(session: session, url: createUser, method: "POST", handle: databaseUser, payload: payload, telemetry: self.telemetry)
158+
return Request(session: session, url: createUser, method: "POST", handle: databaseUser, payload: payload, logger: self.logger, telemetry: self.telemetry)
158159
}
159160

160161
/**
@@ -179,7 +180,7 @@ public struct Authentication: Trackable {
179180
"client_id": self.clientId
180181
]
181182
let resetPassword = NSURL(string: "/dbconnections/change_password", relativeToURL: self.url)!
182-
return Request(session: session, url: resetPassword, method: "POST", handle: noBody, payload: payload, telemetry: self.telemetry)
183+
return Request(session: session, url: resetPassword, method: "POST", handle: noBody, payload: payload, logger: self.logger, telemetry: self.telemetry)
183184
}
184185

185186
/**
@@ -273,7 +274,7 @@ public struct Authentication: Trackable {
273274
}
274275

275276
let start = NSURL(string: "/passwordless/start", relativeToURL: self.url)!
276-
return Request(session: session, url: start, method: "POST", handle: noBody, payload: payload, telemetry: self.telemetry)
277+
return Request(session: session, url: start, method: "POST", handle: noBody, payload: payload, logger: self.logger, telemetry: self.telemetry)
277278
}
278279

279280
/**
@@ -309,7 +310,7 @@ public struct Authentication: Trackable {
309310
"client_id": self.clientId,
310311
]
311312
let start = NSURL(string: "/passwordless/start", relativeToURL: self.url)!
312-
return Request(session: session, url: start, method: "POST", handle: noBody, payload: payload, telemetry: self.telemetry)
313+
return Request(session: session, url: start, method: "POST", handle: noBody, payload: payload, logger: self.logger, telemetry: self.telemetry)
313314
}
314315

315316
/**
@@ -329,7 +330,7 @@ public struct Authentication: Trackable {
329330
public func tokenInfo(token token: String) -> Request<Profile, AuthenticationError> {
330331
let payload: [String: AnyObject] = ["id_token": token]
331332
let tokenInfo = NSURL(string: "/tokeninfo", relativeToURL: self.url)!
332-
return Request(session: session, url: tokenInfo, method: "POST", handle: authenticationObject, payload: payload, telemetry: self.telemetry)
333+
return Request(session: session, url: tokenInfo, method: "POST", handle: authenticationObject, payload: payload, logger: self.logger, telemetry: self.telemetry)
333334
}
334335

335336
/**
@@ -348,7 +349,7 @@ public struct Authentication: Trackable {
348349
*/
349350
public func userInfo(token token: String) -> Request<Profile, AuthenticationError> {
350351
let userInfo = NSURL(string: "/userinfo", relativeToURL: self.url)!
351-
return Request(session: session, url: userInfo, method: "GET", handle: authenticationObject, headers: ["Authorization": "Bearer \(token)"], telemetry: self.telemetry)
352+
return Request(session: session, url: userInfo, method: "GET", handle: authenticationObject, headers: ["Authorization": "Bearer \(token)"], logger: self.logger, telemetry: self.telemetry)
352353
}
353354

354355
/**
@@ -386,7 +387,7 @@ public struct Authentication: Trackable {
386387
]
387388
parameters.forEach { key, value in payload[key] = value }
388389
let accessToken = NSURL(string: "/oauth/access_token", relativeToURL: self.url)!
389-
return Request(session: session, url: accessToken, method: "POST", handle: authenticationObject, payload: payload, telemetry: self.telemetry)
390+
return Request(session: session, url: accessToken, method: "POST", handle: authenticationObject, payload: payload, logger: self.logger, telemetry: self.telemetry)
390391
}
391392

392393

@@ -411,7 +412,7 @@ public struct Authentication: Trackable {
411412
]
412413
parameters.forEach { payload[$0] = $1 }
413414
let token = NSURL(string: "/oauth/token", relativeToURL: self.url)!
414-
return Request(session: session, url: token, method: "POST", handle: authenticationObject, payload: payload, telemetry: self.telemetry)
415+
return Request(session: session, url: token, method: "POST", handle: authenticationObject, payload: payload, logger: self.logger, telemetry: self.telemetry)
415416
}
416417

417418
/**

‎Auth0/Logger/_ObjectiveLogger.swift ‎Auth0/Logger/Loggable.swift

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// _ObjectiveLogger.swift
1+
// Loggable.swift
22
//
33
// Copyright (c) 2016 Auth0 (http://auth0.com)
44
//
@@ -22,26 +22,39 @@
2222

2323
import Foundation
2424

25-
@objc(A0Logger)
26-
public class _ObjectiveLogger: NSObject {
25+
public protocol Loggable {
26+
27+
var logger: Logger? { get set }
28+
29+
}
30+
31+
public extension Loggable {
32+
2733
/**
28-
Turn on Auth0.swift debug logging of HTTP requests and OAuth2 flow (iOS only).
34+
Turn on Auth0.swift debug logging of HTTP requests and OAuth2 flow (iOS only) with a custom logger.
2935

36+
- parameter logger: logger used to print log statements
3037
- note: By default all logging is **disabled**
3138
- important: Logging should be turned on/off **before** making request to Auth0 for the flag to take effect.
3239
*/
33-
public static func loggingEnabled() {
34-
enableLogging(enabled: true)
40+
mutating func usingLogger(logger: Logger) -> Self {
41+
self.logger = logger
42+
return self
3543
}
3644

3745
/**
3846
Turn on/off Auth0.swift debug logging of HTTP requests and OAuth2 flow (iOS only).
3947

40-
- parameter enabled: flag to turn on/off logging
48+
- parameter enabled: optional flag to turn on/off logging
4149
- note: By default all logging is **disabled**
4250
- important: Logging should be turned on/off **before** making request to Auth0 for the flag to take effect.
4351
*/
44-
public static func loggingEnabled(enabled: Bool) {
45-
enableLogging(enabled: enabled)
52+
mutating func logging(enabled enabled: Bool) -> Self {
53+
if enabled {
54+
self.logger = DefaultLogger()
55+
} else {
56+
self.logger = nil
57+
}
58+
return self
4659
}
4760
}

0 commit comments

Comments
 (0)
Please sign in to comment.