Skip to content

Commit

Permalink
Update property names, use static publicClaims
Browse files Browse the repository at this point in the history
  • Loading branch information
cocojoe committed Jun 12, 2017
1 parent fad7d1f commit 0946448
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions App/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ViewController: UIViewController {
}

@IBAction func startOAuth2(_ sender: Any) {
print(UserInfo.publicClaims)
var auth0 = Auth0.webAuth()
auth0
.logging(enabled: true)
Expand Down
18 changes: 8 additions & 10 deletions Auth0/UserInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import Foundation
/// - note: [Claims](https://auth0.com/docs/protocols/oidc#claims)
public class UserInfo: NSObject, JSONObjectPayload {

public static let publicClaims = ["sub", "name", "given_name", "family_name", "middle_name", "nickname", "preferred_username", "profile", "picture", "website", "email", "email_verified", "gender", "birthdate", "zoneinfo", "locale", "phone_number", "phone_number_verified", "address", "updated_at"]

public let sub: String

public let name: String?
Expand Down Expand Up @@ -54,9 +56,9 @@ public class UserInfo: NSObject, JSONObjectPayload {
public let address: [String: String]?
public let updatedAt: Date?

public let additional: [String: Any]?
public let customClaims: [String: Any]?

required public init(sub: String, name: String?, givenName: String?, familyName: String?, middleName: String?, nickname: String?, preferredUsername: String?, profile: URL?, picture: URL?, website: URL?, email: String?, emailVerified: Bool?, gender: String?, birthdate: String?, zoneinfo: TimeZone?, locale: Locale?, phoneNumber: String?, phoneNumberVerified: Bool?, address: [String: String]?, updatedAt: Date?, additional: [String: Any]?) {
required public init(sub: String, name: String?, givenName: String?, familyName: String?, middleName: String?, nickname: String?, preferredUsername: String?, profile: URL?, picture: URL?, website: URL?, email: String?, emailVerified: Bool?, gender: String?, birthdate: String?, zoneinfo: TimeZone?, locale: Locale?, phoneNumber: String?, phoneNumberVerified: Bool?, address: [String: String]?, updatedAt: Date?, customClaims: [String: Any]?) {
self.sub = sub

self.name = name
Expand Down Expand Up @@ -85,7 +87,7 @@ public class UserInfo: NSObject, JSONObjectPayload {

self.updatedAt = updatedAt

self.additional = additional
self.customClaims = customClaims
}

convenience required public init?(json: [String: Any]) {
Expand Down Expand Up @@ -128,13 +130,9 @@ public class UserInfo: NSObject, JSONObjectPayload {
updatedAt = date(from: dateString)
}

let keys = Set(["sub", "name", "given_name", "family_name", "middle_name", "nickname", "preferred_username", "profile", "picture", "website", "email", "email_verified", "gender", "birthdate", "zoneinfo", "locale",
"phone_number", "phone_number_verified", "address", "updated_at"])
var additional = json
keys.forEach {
additional[$0] = nil
}
var customClaims = json
UserInfo.publicClaims.forEach { customClaims.removeValue(forKey: $0) }

self.init(sub: sub, name: name, givenName: givenName, familyName: familyName, middleName: middleName, nickname: nickname, preferredUsername: preferredUsername, profile: profile, picture: picture, website: website, email: email, emailVerified: emailVerified, gender: gender, birthdate: birthdate, zoneinfo: zoneinfo, locale: locale, phoneNumber: phoneNumber, phoneNumberVerified: phoneNumberVerified, address: address, updatedAt: updatedAt, additional: additional)
self.init(sub: sub, name: name, givenName: givenName, familyName: familyName, middleName: middleName, nickname: nickname, preferredUsername: preferredUsername, profile: profile, picture: picture, website: website, email: email, emailVerified: emailVerified, gender: gender, birthdate: birthdate, zoneinfo: zoneinfo, locale: locale, phoneNumber: phoneNumber, phoneNumberVerified: phoneNumberVerified, address: address, updatedAt: updatedAt, customClaims: customClaims)
}
}

0 comments on commit 0946448

Please sign in to comment.