StitchAuth
public protocol StitchAuth
The StitchAuth provides methods for retrieving or modifying the authentication
state of a StitchAppClient.
Each StitchAppClient has an instance of StitchAuth.
Information about the logged-in StitchUser is available in the currentUser property.
To watch for auth events, add a StitchAuthDelegate.
-
Whether or not the client containing this
StitchAuthobject is currently authenticated.Declaration
Swift
var isLoggedIn: Bool { get } -
A
StitchUserobject representing the user that the client is currently authenticated as.nilif the client is not currently authenticated.Declaration
Swift
var currentUser: StitchUser? { get }
-
Retrieves the authenticated authentication provider client for the authentication provider associated with the specified factory.
Declaration
Swift
func providerClient<Factory>(fromFactory factory: Factory) -> Factory.ClientT where Factory : AuthProviderClientFactory, Factory.RequestClientT == StitchAuthRequestClientParameters
fromFactoryThe
AuthProviderClientFactorywhich will provide the client for this authentication provider. Each authentication provider that has extra functionality beyond logging in/linking will offer a static factory which can be used for this method.Return Value
an authentication provider client whose type is determined by the
Clienttypealias in the type specified in thefromFactoryparameter. -
Retrieves the authentication provider client for the authentication provider associated with the specified factory.
Declaration
Swift
func providerClient<Factory>(fromFactory factory: Factory) -> Factory.ClientT where Factory : AuthProviderClientFactory, Factory.RequestClientT == StitchRequestClientParameters
fromFactoryThe
AuthProviderClientFactorywhich will provide the client for this authentication provider. Each authentication provider that has extra functionality beyond logging in/linking will offer a static factory which can be used for this method.Return Value
an authentication provider client whose type is determined by the
Clienttypealias in the type specified in thefromFactoryparameter. -
Retrieves the authenticated authentication provider client for the authentication provider associated with the specified name and factory.
Declaration
Swift
func providerClient<Factory>(fromFactory factory: Factory, withName name: String) -> Factory.Client where Factory : NamedAuthProviderClientFactoryParameters
fromFactoryThe
NamedAuthProviderClientFactorywhich will provide the client for this authentication provider. Each named authentication provider that has extra functionality beyond logging in/linking will offer a static factory which can be used for this method.withNameThe name of the authentication provider as defined in the MongoDB Stitch application.
Return Value
an authentication provider client whose type is determined by the
Clienttypealias in the type specified in thefromFactoryparameter.
-
Authenticates the client as a MongoDB Stitch user using the provided
StitchCredential. On success, this user will become the active user.Declaration
Swift
func login(withCredential credential: StitchCredential, _ completionHandler: @escaping (StitchResult<StitchUser>) -> Void)Parameters
withCredentialThe
StitchCredentialused to authenticate the client. Credentials can be retrieved from an authentication provider client, which is retrieved using theproviderClientmethod.completionHandlerThe completion handler to call when the login is complete. This handler is executed on a non-main global
DispatchQueue. If the operation is successful, the result will contain aStitchUserobject representing the user that the client is now authenticated as. -
Logs out the currently authenticated user, and clears any persisted authentication information.
Declaration
Swift
func logout(_ completionHandler: @escaping (StitchResult<Void>) -> Void)Parameters
completionHandlerThe completion handler to call when the logout is complete. This handler is executed on a non-main global
DispatchQueue. -
Logs out of the user with the given userId. The user must exist in the list of all users who have logged into this application otherwise this will throw a StitchServiveError.
Declaration
Swift
func logoutUser(withId userId: String, _ completionHandler: @escaping (StitchResult<Void>) -> Void)Parameters
userIdA String specifying the desired
userIdcompletionHandlerThe completion handler to call when the switch is complete. This handler is executed on a non-main global
DispatchQueue. -
Switches the active user to the user with the specified id. The user must exist in the list of all users who have logged into this application, and the user must be currently logged in, otherwise this will throw a StitchServiveError.
Declaration
Swift
func switchToUser(withId userId: String) throws -> StitchUserParameters
userIdA String specifying the desired
userId -
Removes the current active user from the list of all users associated with this application. If there is no currently active user, then the function will return with success. Additionally, this method will clear all user data including any synchronized databases.
Declaration
Swift
func removeUser(_ completionHandler: @escaping (StitchResult<Void>) -> Void)Parameters
completionHandlerThe completion handler to call when the switch is complete. This handler is executed on a non-main global
DispatchQueue. -
Removes the user with the provided id from the list of all users associated with this application. If the user was logged in, the user will be logged out before being removed. The user must exist in the list of all users who have logged into this application otherwise this will throw a StitchServiveError. Additionally, this method will clear all user data including any synchronized databases.
Declaration
Swift
func removeUser(withId userId: String, _ completionHandler: @escaping (StitchResult<Void>) -> Void)Parameters
userIdA String specifying the desired
userIdcompletionHandlerThe completion handler to call when the switch is complete. This handler is executed on a non-main global
DispatchQueue. -
Returns a list of all users who have logged into this application, with the exception of those that have been removed manually and anonymous users who have logged out. This list is guaranteed to be in the order that the users were added to the application.
Declaration
Swift
func listUsers() -> [StitchUser]Parameters
completionHandlerThe completion handler to call when the switch is complete. This handler is executed on a non-main global
DispatchQueue.
-
Registers a
StitchAuthDelegatewith the client. TheStitchAuthDelegate‘sonAuthEvent(:fromAuth)method will be called with thisStitchAuthas the argument whenever this client is authenticated or is logged out.Important
StitchAuthDelegates registered here are stored asweakreferences, meaning that if there are no more strong references to a provided delegate, itsonAuthEvent(:fromAuth)method will no longer be called on authentication events.Declaration
Swift
func add(authDelegate: StitchAuthDelegate)Parameters
authDelegateA class conforming to
StitchAuthDelegate, whoseonAuthEvent(:fromAuth)method should be called whenever this client experiences an authentication event.
StitchAuth Protocol Reference