Skip to content

Commit

Permalink
Rename auth transaction classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket committed Nov 2, 2021
1 parent 5a99246 commit 6ebf91c
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 54 deletions.
9 changes: 5 additions & 4 deletions Auth0.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ web_auth_files = [
'Auth0/ObjectiveC/A0SHA.h',
'Auth0/ObjectiveC/A0SHA.m',
'Auth0/Array+Encode.swift',
'Auth0/ASCallbackTransaction.swift',
'Auth0/ASTransaction.swift',
'Auth0/AuthCancelable.swift',
'Auth0/AuthProvider.swift',
'Auth0/AuthSession.swift',
'Auth0/AuthTransaction.swift',
'Auth0/AuthenticationServicesSession.swift',
'Auth0/AuthenticationServicesSessionCallback.swift',
'Auth0/Auth0WebAuth.swift',
'Auth0/BaseCallbackTransaction.swift',
'Auth0/BaseTransaction.swift',

'Auth0/BioAuthentication.swift',
'Auth0/ClaimValidators.swift',
'Auth0/IDTokenSignatureValidator.swift',
Expand All @@ -25,8 +28,6 @@ web_auth_files = [
'Auth0/NSURLComponents+OAuth2.swift',
'Auth0/OAuth2Grant.swift',
'Auth0/ResponseType.swift',
'Auth0/SessionCallbackTransaction.swift',
'Auth0/SessionTransaction.swift',
'Auth0/TransactionStore.swift',
'Auth0/WebAuth.swift',
'Auth0/WebAuthError.swift',
Expand Down
60 changes: 30 additions & 30 deletions Auth0.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// AuthenticationServicesSessionCallback.swift
// ASCallbackTransaction.swift
//
// Copyright (c) 2020 Auth0 (http://auth0.com)
//
Expand All @@ -23,7 +23,7 @@
#if WEB_AUTH_PLATFORM
import AuthenticationServices

final class AuthenticationServicesSessionCallback: SessionCallbackTransaction {
final class ASCallbackTransaction: BaseCallbackTransaction, ASWebAuthenticationPresentationContextProviding {

init(url: URL, schemeURL: URL, callback: @escaping (Bool) -> Void) {
super.init(callback: callback)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// AuthenticationServicesSession.swift
// ASTransaction.swift
//
// Copyright (c) 2020 Auth0 (http://auth0.com)
//
Expand All @@ -23,7 +23,7 @@
#if WEB_AUTH_PLATFORM
import AuthenticationServices

final class AuthenticationServicesSession: SessionTransaction {
final class ASTransaction: BaseTransaction {

init(authorizeURL: URL,
redirectURL: URL,
Expand Down
4 changes: 2 additions & 2 deletions Auth0/Auth0WebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ final class Auth0WebAuth: WebAuth {
state: state,
organization: organization,
invitation: invitation)
let session = AuthenticationServicesSession(authorizeURL: authorizeURL,
let session = ASTransaction(authorizeURL: authorizeURL,
redirectURL: redirectURL,
state: state,
handler: handler,
Expand All @@ -207,7 +207,7 @@ final class Auth0WebAuth: WebAuth {
return callback(false)
}

let session = AuthenticationServicesSessionCallback(url: logoutURL,
let session = ASCallbackTransaction(url: logoutURL,
schemeURL: redirectURL,
callback: callback)
self.storage.store(session)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#if WEB_AUTH_PLATFORM
import Foundation

class SessionCallbackTransaction: NSObject, AuthTransaction {
class BaseCallbackTransaction: NSObject, AuthTransaction {

var authSession: AuthSession?
var state: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#if WEB_AUTH_PLATFORM
import Foundation

class SessionTransaction: NSObject, AuthTransaction {
class BaseTransaction: NSObject, AuthTransaction {

typealias FinishTransaction = (Result<Credentials>) -> Void

var authSession: AuthSession?
let state: String?
let redirectURL: URL
Expand Down Expand Up @@ -55,15 +55,15 @@ class SessionTransaction: NSObject, AuthTransaction {

func handleUrl(_ url: URL) -> Bool {
self.logger?.trace(url: url, source: "iOS Safari")
if self.resume(url) {
if self.resumeAuth(url) {
authSession?.cancel()
authSession = nil
return true
}
return false
}

private func resume(_ url: URL) -> Bool {
private func resumeAuth(_ url: URL) -> Bool {
guard url.absoluteString.lowercased().hasPrefix(self.redirectURL.absoluteString.lowercased()) else { return false }
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
self.callback(.failure(AuthenticationError(string: url.absoluteString, statusCode: 200)))
Expand Down
6 changes: 3 additions & 3 deletions Auth0/DesktopWebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public protocol AuthResumable {

}

extension AuthTransaction where Self: SessionCallbackTransaction {
extension AuthTransaction where Self: BaseCallbackTransaction {

func resume(_ url: URL) -> Bool {
return self.handleUrl(url)
Expand All @@ -77,15 +77,15 @@ extension AuthTransaction where Self: SessionCallbackTransaction {
}

#if swift(>=5.1)
extension AuthenticationServicesSession: ASWebAuthenticationPresentationContextProviding {
extension ASTransaction: ASWebAuthenticationPresentationContextProviding {

func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return NSApplication.shared()?.windows.filter({ $0.isKeyWindow }).last ?? ASPresentationAnchor()
}

}

extension AuthenticationServicesSessionCallback: ASWebAuthenticationPresentationContextProviding {
extension ASCallbackTransaction: ASWebAuthenticationPresentationContextProviding {

func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return NSApplication.shared()?.windows.filter({ $0.isKeyWindow }).last ?? ASPresentationAnchor()
Expand Down
6 changes: 3 additions & 3 deletions Auth0/MobileWebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public extension AuthResumable {

}

extension AuthTransaction where Self: SessionCallbackTransaction {
extension AuthTransaction where Self: BaseCallbackTransaction {

func resume(_ url: URL, options: [A0URLOptionsKey: Any]) -> Bool {
return self.handleUrl(url)
Expand All @@ -102,7 +102,7 @@ extension AuthTransaction where Self: SessionCallbackTransaction {

#if swift(>=5.1)
@available(iOS 13.0, *)
extension AuthenticationServicesSession: ASWebAuthenticationPresentationContextProviding {
extension ASTransaction: ASWebAuthenticationPresentationContextProviding {

func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return UIApplication.shared()?.windows.filter({ $0.isKeyWindow }).last ?? ASPresentationAnchor()
Expand All @@ -111,7 +111,7 @@ extension AuthenticationServicesSession: ASWebAuthenticationPresentationContextP
}

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

func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return UIApplication.shared()?.windows.filter({ $0.isKeyWindow }).last ?? ASPresentationAnchor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ private let Issuer = "\(Domain.absoluteString)/"
private let Leeway = 60 * 1000
private let RedirectURL = URL(string: "https://samples.auth0.com/callback")!

class SessionTransactionSpec: QuickSpec {
class BaseTransactionSpec: QuickSpec {

override func spec() {
var transaction: SessionTransaction!
var transaction: BaseTransaction!
var result: Result<Credentials>? = nil
let callback: (Result<Credentials>) -> () = { result = $0 }
let authentication = Auth0Authentication(clientId: ClientId, url: Domain)
Expand All @@ -55,7 +55,7 @@ class SessionTransactionSpec: QuickSpec {
let code = "123456"

beforeEach {
transaction = SessionTransaction(redirectURL: RedirectURL,
transaction = BaseTransaction(redirectURL: RedirectURL,
state: "state",
handler: handler,
logger: nil,
Expand Down

0 comments on commit 6ebf91c

Please sign in to comment.