-
The Management API token.
Declaration
Swift
var token: String { get }
-
The Auth0 Domain URL.
Declaration
Swift
var url: URL { get }
-
get(_:
Default implementationfields: include: ) Fetches a user using its identifier.
By default it gets all the user’s attributes:
Auth0 .users(token: credentials.accessToken, domain: "samples.auth0.com") .get("user id") .start { result in switch result { case .success(let user): print("Obtained user: \(user)") case .failure(let error): print("Failed with: \(error)") } }
You can select which attributes you want:
Auth0 .users(token: credentials.accessToken, domain: "samples.auth0.com") .get("user id", fields: ["email", "user_id"]) .start { print($0) }
You can even exclude some attributes:
Auth0 .users(token: credentials.accessToken, domain: "samples.auth0.com") .get("user id", fields: ["identities", "app_metadata"], include: false) .start { print($0) }
Requires
The token must have the scoperead:users
scope.Default Implementation
Declaration
Swift
func get(_ identifier: String, fields: [String], include: Bool) -> Request<ManagementObject, ManagementError>
Parameters
identifier
ID of the user. You can get this value from the
sub
claim of the user’s ID Token, or from thesub
property of aUserInfo
instance.fields
List of the user’s field names that will be included/excluded in the response. By default all will be retrieved.
include
Flag that indicates that only the names in ‘fields’ should be included/excluded in the response. By default it will include them.
Return Value
A request that will yield a user.
-
Updates a user’s root values (those which are allowed to be updated).
For example if you need to change
email
:let attributes = UserPatchAttributes().email("newemail@auth0.com", connection: "Username-Password-Authentication", clientId: clientId)
Or if you need to change
user_metadata
:let attributes = UserPatchAttributes().userMetadata(["first_name": "John", "last_name": "Appleseed"])
You can even chain several changes together:
let attributes = UserPatchAttributes() .email("newemail@auth0.com", verify: true, connection: "Username-Password-Authentication", clientId: clientId) .userMetadata(["first_name": "John", "last_name": "Appleseed"]) .appMetadata(["role": "admin"])
Then, just pass the
UserPatchAttributes
to the patch method:Auth0 .users(token: credentials.accessToken, domain: "samples.auth0.com") .patch("user id", attributes: attributes) .start { print($0) }
Requires
The token must have one of the following scopes:update:users
,update:users_app_metadata
.Declaration
Swift
func patch(_ identifier: String, attributes: UserPatchAttributes) -> Request<ManagementObject, ManagementError>
Parameters
identifier
ID of the user to update. You can get this value from the
sub
claim of the user’s ID Token, or from thesub
property of aUserInfo
instance.attributes
Root attributes to be updated.
Return Value
A request that will yield the updated user.
-
Updates only the user’s
user_metadata
field.Auth0 .users(token: credentials.accessToken, domain: "samples.auth0.com") .patch("user id", userMetadata: ["first_name": "John", "last_name": "Appleseed"]) .start { print($0) }
Requires
The token must have one of the following scopes:update:users
,update:users_app_metadata
.Declaration
Swift
func patch(_ identifier: String, userMetadata: [String : Any]) -> Request<ManagementObject, ManagementError>
Parameters
identifier
ID of the user to update. You can get this value from the
sub
claim of the user’s ID Token, or from thesub
property of aUserInfo
instance.userMetadata
Metadata to update.
Return Value
A request that will yield the updated user.
-
Links a user given its identifier with a secondary user given its ID Token. After this request the primary user will hold another identity in its
identities
attribute, which will represent the secondary user.Auth0 .users(token: credentials.accessToken, domain: "samples.auth0.com") .link("primary user id", withOtherUserToken: "secondary id token") .start { print($0) }
Requires
The token must have the scopeupdate:current_user_identities
.Declaration
Swift
func link(_ identifier: String, withOtherUserToken token: String) -> Request<[ManagementObject], ManagementError>
Parameters
identifier
ID of the primary user who will be linked against a secondary one. You can get this value from the
sub
claim of the primary user’s ID Token, or from thesub
property of aUserInfo
instance.token
ID Token of the secondary user.
Return Value
A request to link two users.
-
link(_:
Default implementationwithUser: provider: connectionId: ) Links a user given its identifier with a secondary user given its identifier, provider and connection identifier.
Auth0 .users(token: credentials.accessToken, domain: "samples.auth0.com") .link("primary user id", userId: "secondary user id", provider: "auth0", connectionId: "connection id") .start { print($0) }
Requires
The token must have the scopeupdate:users
.Default Implementation
Declaration
Swift
func link(_ identifier: String, withUser userId: String, provider: String, connectionId: String?) -> Request<[ManagementObject], ManagementError>
Parameters
identifier
ID of the primary user who will be linked against a secondary one. You can get this value from the
sub
claim of the primary user’s ID Token, or from thesub
property of aUserInfo
instance.userId
ID of the secondary user. You can get this value from the
sub
claim of the secondary user’s ID Token, or from thesub
property of aUserInfo
instance.provider
Name of the provider for the secondary user, e.g. ‘auth0’ for database connections.
connectionId
ID of the connection for the secondary user.
Return Value
A request to link two users.
-
Removes an identity from a user.
Auth0 .users(token: credentials.accessToken, domain: "samples.auth0.com") .unlink(identityId: "identity id", provider: "facebook", fromUserId: "user id") .start { print($0) }
Requires
The token must have the scopeupdate:users
.Declaration
Swift
func unlink(identityId: String, provider: String, fromUserId identifier: String) -> Request<[ManagementObject], ManagementError>
Parameters
identityId
ID of the identity to remove.
provider
Name of the identity provider.
identifier
ID of the user who owns the identity. You can get this value from the
sub
claim of the user’s ID Token, or from thesub
property of aUserInfo
instance.Return Value
A request to remove an identity.