Skip to content

Commit

Permalink
Add support for iOS extensions (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket authored Mar 19, 2020
1 parent a232df3 commit 6cdaa5b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Auth0.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ web_auth_files = [
'Auth0/IDTokenValidatorContext.swift',
'Auth0/JWT+Header.swift',
'Auth0/JWK+RSA.swift',
'Auth0/JWTAlgorithm.swift'
'Auth0/JWTAlgorithm.swift',
'Auth0/UIApplication+Shared.swift'
]

watchos_exclude_files = [
Expand Down
4 changes: 4 additions & 0 deletions Auth0.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
5C29743523FDBF5500BC18FA /* JWTDecode.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5C4F554923C9187E00C89615 /* JWTDecode.framework */; };
5C29743623FDBF6700BC18FA /* JWTDecode.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5C4F554723C9177500C89615 /* JWTDecode.framework */; };
5C29743723FDBF7F00BC18FA /* JWTDecode.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5C4F554B23C9189700C89615 /* JWTDecode.framework */; };
5C3BBAB92412CB100017FAEE /* UIApplication+Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C3BBAB82412CB100017FAEE /* UIApplication+Shared.swift */; };
5C49EB3523EB5A80008D562F /* JWK+RSA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C49EB3423EB5A80008D562F /* JWK+RSA.swift */; };
5C4F550723C8FADF00C89615 /* A0SHA.m in Sources */ = {isa = PBXBuildFile; fileRef = 5C4F550223C8FADE00C89615 /* A0SHA.m */; };
5C4F550823C8FADF00C89615 /* A0SHA.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C4F550323C8FADE00C89615 /* A0SHA.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -461,6 +462,7 @@
5BEDE1891EC21B040007300D /* CredentialsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CredentialsManager.swift; sourceTree = "<group>"; };
5BEDE1931EC3331A0007300D /* CredentialsManagerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = CredentialsManagerSpec.swift; path = Auth0Tests/CredentialsManagerSpec.swift; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
5BFB98A41F7D1232001FE50D /* SafariAuthenticationCallback.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SafariAuthenticationCallback.swift; sourceTree = "<group>"; };
5C3BBAB82412CB100017FAEE /* UIApplication+Shared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Shared.swift"; sourceTree = "<group>"; };
5C49EB3423EB5A80008D562F /* JWK+RSA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JWK+RSA.swift"; sourceTree = "<group>"; };
5C4F550223C8FADE00C89615 /* A0SHA.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0SHA.m; sourceTree = "<group>"; };
5C4F550323C8FADE00C89615 /* A0SHA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = A0SHA.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1042,6 +1044,7 @@
5C4F552723C9116B00C89615 /* A0SimpleKeychain+RSAPublicKey.swift */,
5CB41D6B23D0BBA500074024 /* JWT+Header.swift */,
5C49EB3423EB5A80008D562F /* JWK+RSA.swift */,
5C3BBAB82412CB100017FAEE /* UIApplication+Shared.swift */,
);
name = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1760,6 +1763,7 @@
5B6269EA1E3F9E5200305093 /* AuthProvider.swift in Sources */,
5FDE876D1D8A424700EA27DC /* Handlers.swift in Sources */,
5FF2866F1D8A417B00314B72 /* _ObjectiveWebAuth.swift in Sources */,
5C3BBAB92412CB100017FAEE /* UIApplication+Shared.swift in Sources */,
5FE2F8BB1CD0EAAD003628F4 /* Response.swift in Sources */,
5FCCC31C1CF51DF300901E2E /* _ObjectiveManagementAPI.swift in Sources */,
5FDE87591D8A424700EA27DC /* Authentication.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Auth0/ControllerModalPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import UIKit
struct ControllerModalPresenter {

var rootViewController: UIViewController? {
return UIApplication.shared.keyWindow?.rootViewController
return UIApplication.shared()?.keyWindow?.rootViewController
}

func present(controller: UIViewController) {
Expand Down
2 changes: 1 addition & 1 deletion Auth0/SafariAuthenticationCallback.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SafariAuthenticationSessionCallback: NSObject, AuthTransaction {
@available(iOS 13.0, *)
extension SafariAuthenticationSessionCallback: ASWebAuthenticationPresentationContextProviding {
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return UIApplication.shared.keyWindow ?? ASPresentationAnchor()
return UIApplication.shared()?.keyWindow ?? ASPresentationAnchor()
}
}
#endif
2 changes: 1 addition & 1 deletion Auth0/SafariAuthenticationSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class SafariAuthenticationSession: AuthSession {
@available(iOS 13.0, *)
extension SafariAuthenticationSession: ASWebAuthenticationPresentationContextProviding {
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return UIApplication.shared.keyWindow ?? ASPresentationAnchor()
return UIApplication.shared()?.keyWindow ?? ASPresentationAnchor()
}
}
#endif
30 changes: 30 additions & 0 deletions Auth0/UIApplication+Shared.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// UIApplication+Shared.swift
//
// Copyright (c) 2020 Auth0 (http://auth0.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import Foundation
import UIKit

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

0 comments on commit 6cdaa5b

Please sign in to comment.