Skip to content

Commit

Permalink
feat: added support for visionOS platform (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
desusai7 committed Jul 5, 2024
1 parent 0d0fe35 commit 68ed287
Show file tree
Hide file tree
Showing 55 changed files with 2,417 additions and 1,333 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ jobs:

pod-lint:
name: Lint podspec using Xcode ${{ matrix.xcode }}
runs-on: macos-13
runs-on: macos-13-xlarge

strategy:
matrix:
xcode:
- '15.0.1'
- '15.2'

steps:
- name: Checkout
Expand Down
16 changes: 10 additions & 6 deletions Auth0.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Pod::Spec.new do |s|
s.version = '2.8.0'
s.summary = "Auth0 SDK for Apple platforms"
s.description = <<-DESC
Auth0 SDK for iOS, macOS, tvOS, and watchOS apps.
Auth0 SDK for iOS, macOS, tvOS, watchOS and visionOS apps.
DESC
s.homepage = 'https://github.com/auth0/Auth0.swift'
s.license = 'MIT'
Expand All @@ -42,22 +42,26 @@ Pod::Spec.new do |s|
s.social_media_url = 'https://twitter.com/auth0'
s.source_files = 'Auth0/*.swift'
s.resource_bundles = { s.name => 'Auth0/PrivacyInfo.xcprivacy' }
s.swift_versions = ['5.7', '5.8']
s.swift_versions = ['5.9']

s.dependency 'SimpleKeychain', '~> 1.1'
s.dependency 'JWTDecode', '~> 3.1'
s.dependency 'SimpleKeychain', '1.2.0-beta.0'
s.dependency 'JWTDecode', '3.2.0-beta.0'

s.ios.deployment_target = '13.0'
s.ios.deployment_target = '14.0'
s.ios.exclude_files = macos_files
s.ios.pod_target_xcconfig = { 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => 'WEB_AUTH_PLATFORM' }

s.osx.deployment_target = '11.0'
s.osx.exclude_files = ios_files
s.osx.pod_target_xcconfig = { 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => 'WEB_AUTH_PLATFORM' }

s.tvos.deployment_target = '13.0'
s.tvos.deployment_target = '14.0'
s.tvos.exclude_files = excluded_files

s.watchos.deployment_target = '7.0'
s.watchos.exclude_files = excluded_files

s.visionos.deployment_target = '1.0'
s.visionos.exclude_files = macos_files
s.visionos.pod_target_xcconfig = { 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => 'WEB_AUTH_PLATFORM' }
end
873 changes: 842 additions & 31 deletions Auth0.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions Auth0.xcodeproj/xcshareddata/xcschemes/Auth0.visionOS.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C1B3B9BF2C24B39E004A32A4"
BuildableName = "Auth0.framework"
BlueprintName = "Auth0.visionOS"
ReferencedContainer = "container:Auth0.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C1B3B9BF2C24B39E004A32A4"
BuildableName = "Auth0.framework"
BlueprintName = "Auth0.visionOS"
ReferencedContainer = "container:Auth0.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
2 changes: 1 addition & 1 deletion Auth0/ASProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension WebAuthentication {
let session: ASWebAuthenticationSession

#if compiler(>=5.10)
if #available(iOS 17.4, macOS 14.4, *) {
if #available(iOS 17.4, macOS 14.4, visionOS 1.2, *) {
if redirectURL.scheme == "https" {
session = ASWebAuthenticationSession(url: url,
callback: .https(host: redirectURL.host!,
Expand Down
4 changes: 3 additions & 1 deletion Auth0/Auth0WebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ final class Auth0WebAuth: WebAuth {

#if os(macOS)
private let platform = "macos"
#else
#elseif os(iOS)
private let platform = "ios"
#else
private let platform = "visionos"
#endif
private let responseType = "code"

Expand Down
21 changes: 16 additions & 5 deletions Auth0/MobileWebAuth.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
#if os(iOS)
#if os(iOS) || os(visionOS)
import UIKit
import AuthenticationServices

extension UIApplication {

static func shared() -> UIApplication? {
return UIApplication.perform(NSSelectorFromString("sharedApplication"))?.takeUnretainedValue() as? UIApplication
}

}

extension ASUserAgent: ASWebAuthenticationPresentationContextProviding {


#if os(iOS)
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return UIApplication.shared()?.windows.last(where: \.isKeyWindow) ?? ASPresentationAnchor()
}

#endif

#if os(visionOS)
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
if let windowScene = UIApplication.shared()?.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
return windowScene.windows.last(where: \.isKeyWindow) ?? ASPresentationAnchor()
}
return ASPresentationAnchor()
}
#endif

}
#endif
2 changes: 2 additions & 0 deletions Auth0/Telemetry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public struct Telemetry {
return "tvOS"
#elseif os(watchOS)
return "watchOS"
#elseif os(visionOS)
return "visionOS"
#else
return "unknown"
#endif
Expand Down
39 changes: 19 additions & 20 deletions Auth0Tests/ASProviderSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,73 @@ private let CustomSchemeRedirectURL = URL(string: "com.auth0.example://samples.a
private let Timeout: NimbleTimeInterval = .seconds(2)

class ASProviderSpec: QuickSpec {

override func spec() {

override class func spec() {
var session: ASWebAuthenticationSession!
var userAgent: ASUserAgent!

beforeEach {
session = ASWebAuthenticationSession(url: AuthorizeURL, callbackURLScheme: nil, completionHandler: { _, _ in })
userAgent = ASUserAgent(session: session, callback: { _ in })
}

afterEach {
session.cancel()
}

describe("WebAuthentication extension") {

it("should create a web authentication session provider") {
let provider = WebAuthentication.asProvider(redirectURL: HTTPSRedirectURL)
expect(provider(AuthorizeURL, {_ in })).to(beAKindOf(ASUserAgent.self))
}

it("should not use an ephemeral session by default") {
let provider = WebAuthentication.asProvider(redirectURL: CustomSchemeRedirectURL)
userAgent = provider(AuthorizeURL, { _ in }) as? ASUserAgent
expect(userAgent.session.prefersEphemeralWebBrowserSession) == false
}

it("should use an ephemeral session") {
let provider = WebAuthentication.asProvider(redirectURL: CustomSchemeRedirectURL, ephemeralSession: true)
userAgent = provider(AuthorizeURL, { _ in }) as? ASUserAgent
expect(userAgent.session.prefersEphemeralWebBrowserSession) == true
}

}

describe("user agent") {

it("should have a custom description") {
expect(userAgent.description) == "ASWebAuthenticationSession"
}

it("should be the web authentication session's presentation context provider") {
expect(session.presentationContextProvider).to(be(userAgent))
}

it("should call the callback with an error") {
await waitUntil(timeout: Timeout) { done in
waitUntil(timeout: Timeout) { done in
let userAgent = ASUserAgent(session: session, callback: { result in
expect(result).to(beFailure())
done()
})
userAgent.finish(with: .failure(.userCancelled))
}
}

it("should call the callback with success") {
await waitUntil(timeout: Timeout) { done in
waitUntil(timeout: Timeout) { done in
let userAgent = ASUserAgent(session: session, callback: { result in
expect(result).to(beSuccessful())
done()
})
userAgent.finish(with: .success(()))
}
}

}

}

}
2 changes: 1 addition & 1 deletion Auth0Tests/Auth0Spec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private let Token = "TOKEN"

class Auth0Spec: QuickSpec {

override func spec() {
override class func spec() {

describe("global functions") {

Expand Down
Loading

0 comments on commit 68ed287

Please sign in to comment.