From 930c8e3a7e5dc4d4fce11c96688779fae4c38060 Mon Sep 17 00:00:00 2001 From: Martin Walsh Date: Tue, 9 May 2017 14:34:29 +0100 Subject: [PATCH] Rename method, update doc headers --- App/ViewController.swift | 1 - Auth0.podspec | 1 + Auth0.xcodeproj/project.pbxproj | 4 +++ Auth0/SafariWebAuth.swift | 20 ++----------- Auth0/SilentSafariViewController.swift | 40 ++++++++++++++++++++++++++ Auth0/WebAuth.swift | 22 +++++++++----- Auth0Tests/WebAuthSpec.swift | 4 +-- codecov.yml | 4 ++- 8 files changed, 67 insertions(+), 29 deletions(-) create mode 100644 Auth0/SilentSafariViewController.swift diff --git a/App/ViewController.swift b/App/ViewController.swift index 15922065..99bfcaf4 100644 --- a/App/ViewController.swift +++ b/App/ViewController.swift @@ -38,7 +38,6 @@ class ViewController: UIViewController { var auth0 = Auth0.webAuth() auth0 .logging(enabled: true) - .responseType([.token]) .start(onAuth) } diff --git a/Auth0.podspec b/Auth0.podspec index 60f3940b..84ca1169 100644 --- a/Auth0.podspec +++ b/Auth0.podspec @@ -10,6 +10,7 @@ web_auth_files = [ 'Auth0/WebAuthError.swift', 'Auth0/SafariWebAuth.swift', 'Auth0/SafariSession.swift', + 'Auth0/SilentSafariViewController.swift', 'Auth0/NativeAuth.swift', 'Auth0/AuthProvider.swift' ] diff --git a/Auth0.xcodeproj/project.pbxproj b/Auth0.xcodeproj/project.pbxproj index 11da39b7..3a2d4940 100644 --- a/Auth0.xcodeproj/project.pbxproj +++ b/Auth0.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 5B6269E71E3F702000305093 /* NativeAuthSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6269E51E3F700000305093 /* NativeAuthSpec.swift */; }; 5B6269EA1E3F9E5200305093 /* AuthProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6269E91E3F9E5200305093 /* AuthProvider.swift */; }; 5BD4A9CE1DEC6EFA00D6D7AE /* ResponseType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BD4A9CD1DEC6EFA00D6D7AE /* ResponseType.swift */; }; + 5BEDE1571EC1FBBE0007300D /* SilentSafariViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BEDE1561EC1FBBE0007300D /* SilentSafariViewController.swift */; }; 5F06DDA51CC451540011842B /* Auth0.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F06DD781CC448B10011842B /* Auth0.framework */; }; 5F06DDB41CC451700011842B /* Auth0.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F06DD851CC448C90011842B /* Auth0.framework */; }; 5F06DDC91CC66B710011842B /* Auth0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F06DDC81CC66B710011842B /* Auth0.swift */; }; @@ -294,6 +295,7 @@ 5B6269E91E3F9E5200305093 /* AuthProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AuthProvider.swift; path = Auth0/AuthProvider.swift; sourceTree = SOURCE_ROOT; }; 5B9A54411E49E3AE004B5454 /* Auth0.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Auth0.plist; sourceTree = SOURCE_ROOT; }; 5BD4A9CD1DEC6EFA00D6D7AE /* ResponseType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ResponseType.swift; path = Auth0/ResponseType.swift; sourceTree = SOURCE_ROOT; }; + 5BEDE1561EC1FBBE0007300D /* SilentSafariViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SilentSafariViewController.swift; path = Auth0/SilentSafariViewController.swift; sourceTree = SOURCE_ROOT; }; 5F049B6C1CB42C29006F6C05 /* Auth0.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Auth0.h; path = Auth0/Auth0.h; sourceTree = ""; }; 5F049B6E1CB42C29006F6C05 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Auth0/Info.plist; sourceTree = ""; }; 5F06DD781CC448B10011842B /* Auth0.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Auth0.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -608,6 +610,7 @@ 5F4A1F951D00AABC00C72242 /* OAuth2Grant.swift */, 5B25A5321E3F68FA00563AE5 /* SafariSession.swift */, 5FAE9C901D8878D400A871CE /* SafariWebAuth.swift */, + 5BEDE1561EC1FBBE0007300D /* SilentSafariViewController.swift */, 5FCAB1751D0900CF00331C84 /* TransactionStore.swift */, 5F3965C11CF67CF000CDE7C0 /* WebAuth.swift */, 5FD255B91D14F70B00387ECB /* WebAuthError.swift */, @@ -1246,6 +1249,7 @@ 5FD255B71D14F00900387ECB /* Auth0Error.swift in Sources */, 5F06DDC91CC66B710011842B /* Auth0.swift in Sources */, 5FDE87691D8A424700EA27DC /* Credentials.swift in Sources */, + 5BEDE1571EC1FBBE0007300D /* SilentSafariViewController.swift in Sources */, 5FDE87651D8A424700EA27DC /* Profile.swift in Sources */, 5FE2F8B21CCEAED8003628F4 /* Requestable.swift in Sources */, 5F7504F51D8C3F2900E3BA1C /* NSError+Helper.swift in Sources */, diff --git a/Auth0/SafariWebAuth.swift b/Auth0/SafariWebAuth.swift index 493bc4a2..d2ad9b53 100644 --- a/Auth0/SafariWebAuth.swift +++ b/Auth0/SafariWebAuth.swift @@ -183,9 +183,9 @@ class SafariWebAuth: WebAuth { .appendingPathComponent("callback") } - func logout(useFederated federated: Bool = false, callback: @escaping (Bool) -> Void) { + func clearSession(federated: Bool, callback: @escaping (Bool) -> Void) { let logoutURL = federated ? URL(string: "/v2/logout?federated", relativeTo: self.url)! : URL(string: "/v2/logout", relativeTo: self.url)! - let controller = SilentSFSafariViewController(url: logoutURL) { callback($0) } + let controller = SilentSafariViewController(url: logoutURL) { callback($0) } logger?.trace(url: logoutURL, source: "Safari") self.presenter.present(controller: controller) } @@ -201,19 +201,3 @@ private func generateDefaultState() -> String? { guard result == 0 else { return nil } return data.a0_encodeBase64URLSafe() } - -private class SilentSFSafariViewController: SFSafariViewController, SFSafariViewControllerDelegate { - var onResult: (Bool) -> Void = { _ in } - - required init(url URL: URL, callback: @escaping (Bool) -> Void) { - super.init(url: URL, entersReaderIfAvailable: false) - self.onResult = callback - self.delegate = self - self.view.alpha = 0.05 // Apple does not allow invisible SafariViews, this is the threshold. - self.modalPresentationStyle = .overCurrentContext - } - - func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) { - controller.dismiss(animated: false) { self.onResult(didLoadSuccessfully) } - } -} diff --git a/Auth0/SilentSafariViewController.swift b/Auth0/SilentSafariViewController.swift new file mode 100644 index 00000000..4545fd2d --- /dev/null +++ b/Auth0/SilentSafariViewController.swift @@ -0,0 +1,40 @@ +// SilentSafariViewController.swift +// +// Copyright (c) 2017 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 UIKit +import SafariServices + +class SilentSafariViewController: SFSafariViewController, SFSafariViewControllerDelegate { + var onResult: (Bool) -> Void = { _ in } + + required init(url URL: URL, callback: @escaping (Bool) -> Void) { + super.init(url: URL, entersReaderIfAvailable: false) + self.onResult = callback + self.delegate = self + self.view.alpha = 0.05 // Apple does not allow invisible SafariViews, this is the threshold. + self.modalPresentationStyle = .overCurrentContext + } + + func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) { + controller.dismiss(animated: false) { self.onResult(didLoadSuccessfully) } + } +} diff --git a/Auth0/WebAuth.swift b/Auth0/WebAuth.swift index 3f6ea643..55ba6c4a 100644 --- a/Auth0/WebAuth.swift +++ b/Auth0/WebAuth.swift @@ -202,18 +202,26 @@ public protocol WebAuth: Trackable, Loggable { func start(_ callback: @escaping (Result) -> Void) /** - Silently clear the SSO Cookie in Auth0 and optionally signout from IdP. - More info: https://auth0.com/docs/logout + Removes Auth0 session and optionally remove the Identity Provider session. + - seeAlso: [Auth0 Logout docs](https://auth0.com/docs/logout) + - ``` Auth0 .webAuth() - .logout(useFederated: false) { print($0) } + .clearSession { print($0) } ``` - - parameter federated: Bool to enable signout of the IdP - - parameter callback: callback called with the result of the logout + Remove Auth0 session and remove the IdP session. + + ``` + Auth0 + .webAuth() + .clearSession(federated: true) { print($0) } + ``` + + - parameter federated: Bool to remove the IdP session + - parameter callback: callback called with bool outcome of the call */ - func logout(useFederated federated: Bool, callback: @escaping (Bool) -> Void) + func clearSession(federated: Bool, callback: @escaping (Bool) -> Void) } diff --git a/Auth0Tests/WebAuthSpec.swift b/Auth0Tests/WebAuthSpec.swift index cfdf15fd..1ff11b51 100644 --- a/Auth0Tests/WebAuthSpec.swift +++ b/Auth0Tests/WebAuthSpec.swift @@ -317,8 +317,8 @@ class WebAuthSpec: QuickSpec { it("should launch silent safari viewcontroller") { let auth = newWebAuth() - auth.logout(useFederated: false) { _ in } - expect(auth.presenter.topViewController is SFSafariViewControllerDelegate).toNot(beNil()) + auth.clearSession(federated: false) { _ in } + expect(auth.presenter.topViewController is SilentSafariViewController).toNot(beNil()) } } } diff --git a/codecov.yml b/codecov.yml index 8efe7c6b..55b48119 100644 --- a/codecov.yml +++ b/codecov.yml @@ -7,10 +7,12 @@ coverage: status: patch: default: + threshold: 50 if_no_uploads: error changes: true project: default: target: auto + threshold: 2 if_no_uploads: error -comment: false \ No newline at end of file +comment: false