From 09464489289366a2c51824d90353b969814b9ef9 Mon Sep 17 00:00:00 2001 From: Martin Walsh Date: Mon, 12 Jun 2017 17:06:04 +0100 Subject: [PATCH] Update property names, use static publicClaims --- App/ViewController.swift | 1 + Auth0/UserInfo.swift | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/App/ViewController.swift b/App/ViewController.swift index 99bfcaf4b..08777cc09 100644 --- a/App/ViewController.swift +++ b/App/ViewController.swift @@ -35,6 +35,7 @@ class ViewController: UIViewController { } @IBAction func startOAuth2(_ sender: Any) { + print(UserInfo.publicClaims) var auth0 = Auth0.webAuth() auth0 .logging(enabled: true) diff --git a/Auth0/UserInfo.swift b/Auth0/UserInfo.swift index 3edc09492..042b3b6b4 100644 --- a/Auth0/UserInfo.swift +++ b/Auth0/UserInfo.swift @@ -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? @@ -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 @@ -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]) { @@ -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) } }