Skip to content
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
4 changes: 2 additions & 2 deletions AppTests/ContentViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct MockAuthentication: Authentication {
var clientId: String
var url: URL
var dpop: DPoP?
var telemetry: Telemetry
var auth0ClientInfo: Auth0ClientInfo
var logger: (any Logger)?

/// The request returned by `login(usernameOrEmail:password:realmOrConnection:audience:scope:)`.
Expand All @@ -50,7 +50,7 @@ struct MockAuthentication: Authentication {
self.clientId = clientId
self.url = url
self.dpop = nil
self.telemetry = Telemetry()
self.auth0ClientInfo = Auth0ClientInfo()
self.logger = nil
}

Expand Down
56 changes: 28 additions & 28 deletions Auth0.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Auth0/APICredentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
private struct _A0APICredentials {
let accessToken: String
let tokenType: String
let expiresIn: Date
let expiresAt: Date
let scope: String
}

Expand All @@ -21,7 +21,7 @@ public struct APICredentials: CustomStringConvertible, Sendable {
public let tokenType: String

/// When the access token expires.
public let expiresIn: Date
public let expiresAt: Date

/// The scopes that have been granted by Auth0.
///
Expand All @@ -35,7 +35,7 @@ public struct APICredentials: CustomStringConvertible, Sendable {
let redacted = "<REDACTED>"
let values = _A0APICredentials(accessToken: redacted,
tokenType: self.tokenType,
expiresIn: self.expiresIn,
expiresAt: self.expiresAt,
scope: self.scope)
return String(describing: values).replacingOccurrences(of: "_A0APICredentials", with: "APICredentials")
}
Expand All @@ -45,11 +45,11 @@ public struct APICredentials: CustomStringConvertible, Sendable {
/// Default initializer.
public init(accessToken: String,
tokenType: String,
expiresIn: Date,
expiresAt: Date,
scope: String) {
self.accessToken = accessToken
self.tokenType = tokenType
self.expiresIn = expiresIn
self.expiresAt = expiresAt
self.scope = scope
}
}
Expand All @@ -61,7 +61,7 @@ extension APICredentials: Codable {
enum CodingKeys: String, CodingKey {
case accessToken = "access_token"
case tokenType = "token_type"
case expiresIn = "expires_in"
case expiresAt = "expires_in"
case scope
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public extension APICredentials {
init(from credentials: Credentials) {
self.accessToken = credentials.accessToken
self.tokenType = credentials.tokenType
self.expiresIn = credentials.expiresIn
self.expiresAt = credentials.expiresAt
self.scope = credentials.scope ?? ""
}

Expand Down
48 changes: 24 additions & 24 deletions Auth0/Auth0Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ struct Auth0Authentication: Authentication {

let clientId: String
let url: URL
var telemetry: Telemetry
var auth0ClientInfo: Auth0ClientInfo
var logger: Logger?
var dpop: DPoP?

let session: URLSession

init(clientId: String, url: URL, session: URLSession = URLSession.shared, telemetry: Telemetry = Telemetry()) {
init(clientId: String, url: URL, session: URLSession = URLSession.shared, auth0ClientInfo: Auth0ClientInfo = Auth0ClientInfo()) {
self.clientId = clientId
self.url = url
self.session = session
self.telemetry = telemetry
self.auth0ClientInfo = auth0ClientInfo
}

func login(email: String, code: String, audience: String?, scope: String) -> any Requestable<Credentials, AuthenticationError> {
Expand Down Expand Up @@ -48,7 +48,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: self.dpop)
}

Expand All @@ -70,7 +70,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: self.dpop)
}

Expand All @@ -90,7 +90,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: self.dpop)
}

Expand All @@ -114,7 +114,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: self.dpop)
}

Expand All @@ -134,7 +134,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: self.dpop)
}

Expand All @@ -159,7 +159,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry)
auth0ClientInfo: self.auth0ClientInfo)
}

func login(appleAuthorizationCode authorizationCode: String,
Expand Down Expand Up @@ -227,7 +227,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDatabaseUser,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry)
auth0ClientInfo: self.auth0ClientInfo)
}

#if PASSKEYS_PLATFORM
Expand Down Expand Up @@ -272,7 +272,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: self.dpop)
}

Expand All @@ -291,7 +291,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry)
auth0ClientInfo: self.auth0ClientInfo)
}

@available(iOS 16.6, macOS 13.5, visionOS 1.0, *)
Expand Down Expand Up @@ -334,7 +334,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: self.dpop)
}

Expand Down Expand Up @@ -366,7 +366,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry)
auth0ClientInfo: self.auth0ClientInfo)
}
#endif

Expand All @@ -383,7 +383,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationNoBody,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry)
auth0ClientInfo: self.auth0ClientInfo)
}

func startPasswordless(email: String, type: PasswordlessType, connection: String) -> any Requestable<Void, AuthenticationError> {
Expand All @@ -401,7 +401,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationNoBody,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry)
auth0ClientInfo: self.auth0ClientInfo)
}

func startPasswordless(phoneNumber: String, type: PasswordlessType, connection: String) -> any Requestable<Void, AuthenticationError> {
Expand All @@ -418,7 +418,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationNoBody,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry)
auth0ClientInfo: self.auth0ClientInfo)
}

func userInfo(withAccessToken accessToken: String, tokenType: String) -> any Requestable<UserProfile, AuthenticationError> {
Expand All @@ -432,7 +432,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationObject,
headers: headers,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: dpop)
}

Expand Down Expand Up @@ -477,7 +477,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: self.dpop)
}

Expand All @@ -493,7 +493,7 @@ struct Auth0Authentication: Authentication {
handle: authenticationNoBody,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry)
auth0ClientInfo: self.auth0ClientInfo)
}

func jwks() -> any Requestable<JWKS, AuthenticationError> {
Expand All @@ -503,7 +503,7 @@ struct Auth0Authentication: Authentication {
method: "GET",
handle: authenticationDecodable,
logger: self.logger,
telemetry: self.telemetry)
auth0ClientInfo: self.auth0ClientInfo)
}

func customTokenExchange(subjectToken: String,
Expand Down Expand Up @@ -545,7 +545,7 @@ private extension Auth0Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: self.dpop)
}

Expand All @@ -571,7 +571,7 @@ private extension Auth0Authentication {
handle: authenticationDecodable,
parameters: parameters,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: dpop)
}

Expand All @@ -585,7 +585,7 @@ private extension Auth0Authentication {
handle: authenticationDecodable,
parameters: payload,
logger: self.logger,
telemetry: self.telemetry,
auth0ClientInfo: self.auth0ClientInfo,
dpop: self.dpop)
}

Expand Down
42 changes: 21 additions & 21 deletions Auth0/Telemetry.swift → Auth0/Auth0ClientInfo.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Generates and sets the `Auth0-Client` header.
public struct Telemetry: Sendable {
public struct Auth0ClientInfo: Sendable {

static let NameKey = "name"
static let VersionKey = "version"
Expand All @@ -17,21 +17,21 @@ public struct Telemetry: Sendable {
return self.enabled ? self.info : nil
}

/// Initializer that generates a base64url-encoded value with telemetry data.
/// Initializer that generates a base64url-encoded value with client info data.
public init() {
self.info = Telemetry.generateValue()
self.info = Auth0ClientInfo.generateValue()
}

mutating func wrapped(inLibrary name: String, version: String) {
let info = Telemetry.versionInformation()
var env = Telemetry.generateEnviroment()
env[Telemetry.WrappedVersion] = info[Telemetry.VersionKey] as? String
let info = Auth0ClientInfo.versionInformation()
var env = Auth0ClientInfo.generateEnviroment()
env[Auth0ClientInfo.WrappedVersion] = info[Auth0ClientInfo.VersionKey] as? String
let wrapped: [String: Any] = [
Telemetry.NameKey: name,
Telemetry.VersionKey: version,
Telemetry.EnvironmentKey: env
Auth0ClientInfo.NameKey: name,
Auth0ClientInfo.VersionKey: version,
Auth0ClientInfo.EnvironmentKey: env
]
self.info = Telemetry.generateValue(fromInfo: wrapped)
self.info = Auth0ClientInfo.generateValue(fromInfo: wrapped)
}

func addTelemetryHeader(request: NSMutableURLRequest) {
Expand All @@ -52,22 +52,22 @@ public struct Telemetry: Sendable {

static func versionInformation() -> [String: Any] {
let dict: [String: Any] = [
Telemetry.NameKey: Telemetry.LibraryName,
Telemetry.VersionKey: version,
Telemetry.EnvironmentKey: Telemetry.generateEnviroment()
Auth0ClientInfo.NameKey: Auth0ClientInfo.LibraryName,
Auth0ClientInfo.VersionKey: version,
Auth0ClientInfo.EnvironmentKey: Auth0ClientInfo.generateEnviroment()
]
return dict
}

static func generateEnviroment() -> [String: String] {
let platform = Telemetry.osInfo()
let env = [ "swift": Telemetry.swiftVersion(),
let platform = Auth0ClientInfo.osInfo()
let env = [ "swift": Auth0ClientInfo.swiftVersion(),
platform.0: platform.1
]
return env
}

static func generateValue(fromInfo info: [String: Any] = Telemetry.versionInformation()) -> String? {
static func generateValue(fromInfo info: [String: Any] = Auth0ClientInfo.versionInformation()) -> String? {
let data = try? JSONSerialization.data(withJSONObject: info, options: [])
return data?.a0_encodeBase64URLSafe()
}
Expand Down Expand Up @@ -100,8 +100,8 @@ public struct Telemetry: Sendable {
/// A type that can send the `Auth0-Client` header on every request to Auth0.
public protocol Trackable {

/// The ``Telemetry`` instance.
var telemetry: Telemetry { get set }
/// The ``Auth0ClientInfo`` instance.
var auth0ClientInfo: Auth0ClientInfo { get set }

}

Expand All @@ -111,10 +111,10 @@ public extension Trackable {
Turn on/off sending the `Auth0-Client` header on every request to Auth0.
By default we collect our libraries and SDKs versions to help us evaluate usage.

- Parameter enabled: Flag to turn telemetry on/off.
- Parameter enabled: Flag to turn the `Auth0-Client` header on/off.
*/
mutating func tracking(enabled: Bool) {
self.telemetry.enabled = enabled
self.auth0ClientInfo.enabled = enabled
}

/**
Expand All @@ -124,7 +124,7 @@ public extension Trackable {
- Parameter version: Version of library or framework.
*/
mutating func using(inLibrary name: String, version: String) {
self.telemetry.wrapped(inLibrary: name, version: version)
self.auth0ClientInfo.wrapped(inLibrary: name, version: version)
}

}
Loading
Loading