Skip to content

Commit 9fd0411

Browse files
committed
Update README.md & CHANGELOG.md
[skip ci]
1 parent faceca8 commit 9fd0411

File tree

2 files changed

+51
-62
lines changed

2 files changed

+51
-62
lines changed

CHANGELOG.md

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,60 @@
22

33
First release of Guardian for iOS
44

5-
### Requirements
6-
7-
iOS 9.3+ and Swift 3 is required in order to use Guardian.
8-
9-
### Install
5+
##Install
106

117
#### CocoaPods
128

139
Guardian.swift is available through [CocoaPods](http://cocoapods.org).
1410
To install it, simply add the following line to your Podfile:
1511

1612
```ruby
17-
pod "Guardian", '~> 0.1.0'
13+
pod "Guardian"
1814
```
1915

2016
#### Carthage
2117

2218
In your Cartfile add this line
2319

2420
```
25-
github "auth0/Guardian.swift" ~> 0.1.0
21+
github "auth0/Guardian.swift"
2622
```
2723

28-
### Usage
24+
## Usage
2925

30-
To get things going you'll have to import the library:
26+
`Guardian` is the core of the SDK. To get things going you'll have to import the library:
3127

3228
```swift
3329
import Guardian
3430
```
3531

36-
Then you'll need the domain for your specific tenant/url:
32+
Then you'll need the Auth0 Guarduan domain for your account:
3733

3834
```swift
39-
let domain = "<TENANT>.guardian.auth0.com"
35+
let domain = "{YOUR_ACCOUNT_NAME}.guardian.auth0.com"
4036
```
4137

42-
To create an enroll, create a pair of RSA keys, obtain the Guardian enrollment data from a Guardian QR code and use it like this:
38+
### Enroll
4339

44-
```swift
45-
let rsaKeyPair = RSAKeyPair.new(usingPublicTag: "com.auth0.guardian.enroll.public",
46-
privateTag: "com.auth0.guardian.enroll.private")
40+
An enrollment is a link between the second factor and an Auth0 account. When an account is enrolled
41+
you'll need it to provide the second factor required to verify the identity.
42+
43+
For an enrollment you need the following things, besides your Guardian Domain:
44+
45+
- Enrollment Uri: The value encoded in the QR Code scanned from Guardian Web Widget or in your enrollment ticket sent to you, e.g. by email.
46+
- APNS Token: Apple APNS token for the device and **MUST** be a `String`containing the 64 bytes (expressed in hexadecimal format)
47+
- Key Pair: A RSA (Private/Public) key pair used to assert your identity with Auth0 Guardian
4748

48-
let enrollmentUriFromQr: String = ... // the URI obtained from a Guardian QR code
49-
let apnsToken: String = ... // the APNS token of this device, where notifications will be sent
49+
> In case your app is not yet using push notifications or you're not familiar with it, you should check their [docs](https://developer.apple.com/go/?id=push-notifications).
5050
51+
after your have all of them, you can enroll your device
52+
53+
```swift
5154
Guardian
52-
.enroll(forDomain: domain,
53-
usingUri: enrollmentUriFromQr,
54-
notificationToken: apnsToken,
55-
keyPair: rsaKeyPair)
55+
.enroll(forDomain: "{YOUR_GUARDIAN_DOMAIN}",
56+
usingUri: "{ENROLLMENT_URI}",
57+
notificationToken: "{APNS_TOKEN}",
58+
keyPair: keyPair)
5659
.start { result in
5760
switch result {
5861
case .success(let enrollment):
@@ -63,62 +66,48 @@ Guardian
6366
}
6467
```
6568

66-
To unenroll just call:
69+
On success you'll obtain the enrollment information, that should be secured stored in your application. This information includes the enrollment identifier, and the token for Guardian API associated to your device for updating or deleting your enrollment.
70+
71+
#### RSA key pair
72+
73+
Guardian.swift provides a convenience class to generate an RSA key pair and store it in iOS Keychain.
6774

6875
```swift
69-
Guardian
70-
.api(forDomain: domain)
71-
.device(forEnrollmentId: enrollment.id, token: enrollment.deviceToken)
72-
.delete()
73-
.start { result in
74-
switch result {
75-
case .success:
76-
// success, the enrollment was deleted
77-
case .failure(let cause):
78-
// something failed, check cause to see what went wrong
79-
}
80-
}
76+
let rsaKeyPair = RSAKeyPair.new(
77+
usingPublicTag: "com.auth0.guardian.enroll.public",
78+
privateTag: "com.auth0.guardian.enroll.private"
79+
)
8180
```
8281

83-
To allow or reject a login request you first need to get the Guardian `Notification`. In your `AppDelegate` add something like this:
82+
> The tags should be unique since it's the identifier of each key inside iOS Keychain.
8483
85-
```swift
86-
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
87-
// when the app is open and we receive a push notification
84+
> Since the keys are already secured stored inside iOS Keychain, you olny need to store the identifiers
8885
89-
if let notification = Guardian.notification(from: userInfo) {
90-
// we have received a Guardian push notification
91-
}
92-
}
93-
```
86+
### Allow a login request
9487

95-
Then, to allow the login request, call:
88+
Once you have the enrollment in place, you will receive a push notification every time the user has to validate his identity with MFA.
89+
90+
Guardian provides a method to parse the data received from APNs and return a `Notification` instance ready to be used.
9691

9792
```swift
98-
Guardian
99-
.authentication(forDomain: domain, andEnrollment: enrollment)
100-
.allow(notification: notification)
101-
.start { result in
102-
switch result {
103-
case .success:
104-
// the auth request was successfuly allowed
105-
case .failure(let cause):
106-
// something failed, check cause to see what went wrong
107-
}
108-
}
93+
if let notification = Guardian.notification(from: userInfo) {
94+
// we have received a Guardian push notification
95+
}
10996
```
11097

111-
or to reject it (optionally you can also indicate a reject reason):
98+
Once you have the notification instance, you can easily allow the authentication request by using
99+
the `allow` method. You'll also need the enrollment that you obtained previously.
100+
In case you have more than one enrollment, you'll have to find the one that has the same `id` as the
101+
notification (the `enrollmentId` property).
112102

113103
```swift
114104
Guardian
115-
.authentication(forDomain: domain, andEnrollment: enrollment)
116-
.reject(notification: notification)
117-
// or .reject(notification: notification, withReason: "hacked")
105+
.authentication(forDomain: "{YOUR_GUARDIAN_DOMAIN}", andEnrollment: enrollment)
106+
.allow(notification: notification)
118107
.start { result in
119108
switch result {
120109
case .success:
121-
// the auth request was successfuly rejected
110+
// the auth request was successfuly allowed
122111
case .failure(let cause):
123112
// something failed, check cause to see what went wrong
124113
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Guardian SDK for iOS
2-
============
3-
[![CI Status](https://travis-ci.org/auth0/Guardian.swift.svg?branch=master)](https://travis-ci.com/auth0/Guardian.swift)
2+
3+
[![CI Status](https://travis-ci.org/auth0/Guardian.swift.svg?branch=master)](https://travis-ci.org/auth0/Guardian.swift)
44
[![License](http://img.shields.io/:license-mit-blue.svg?style=flat)](http://doge.mit-license.org)
55

66
[Guardian](https://auth0.com/docs/multifactor-authentication/guardian) is Auth0's multi-factor

0 commit comments

Comments
 (0)