Skip to content

Commit

Permalink
Rename method, update doc headers
Browse files Browse the repository at this point in the history
  • Loading branch information
cocojoe committed May 17, 2017
1 parent 9e50a99 commit 930c8e3
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 29 deletions.
1 change: 0 additions & 1 deletion App/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class ViewController: UIViewController {
var auth0 = Auth0.webAuth()
auth0
.logging(enabled: true)
.responseType([.token])
.start(onAuth)
}

Expand Down
1 change: 1 addition & 0 deletions Auth0.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Expand Down
4 changes: 4 additions & 0 deletions Auth0.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
5F049B6E1CB42C29006F6C05 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Auth0/Info.plist; sourceTree = "<group>"; };
5F06DD781CC448B10011842B /* Auth0.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Auth0.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
20 changes: 2 additions & 18 deletions Auth0/SafariWebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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) }
}
}
40 changes: 40 additions & 0 deletions Auth0/SilentSafariViewController.swift
Original file line number Diff line number Diff line change
@@ -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) }
}
}
22 changes: 15 additions & 7 deletions Auth0/WebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,26 @@ public protocol WebAuth: Trackable, Loggable {
func start(_ callback: @escaping (Result<Credentials>) -> 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)
}
4 changes: 2 additions & 2 deletions Auth0Tests/WebAuthSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
comment: false

0 comments on commit 930c8e3

Please sign in to comment.