StitchAuth
public protocol StitchAuth
A set of methods for retrieving or modifying the authentication state of a StitchAppClient.
An implementation can be instantiated with a StitchAppClient instance.
-
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.Declaration
Swift
func login(withCredential credential: StitchCredential, _ completionHandler: @escaping (StitchResult<StitchUser>) -> Void)Parameters
withCredentialThe
StitchCredentialused to authenticate the client as a particular user. Each authentication provider has an implementation ofStitchCredentialthat can be used with this method.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.
-
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