Class StitchAuthImpl
- java.lang.Object
-
- com.mongodb.stitch.core.auth.internal.CoreStitchAuth<StitchUser>
-
- com.mongodb.stitch.android.core.auth.internal.StitchAuthImpl
-
- All Implemented Interfaces:
StitchAuth,StitchAuthRequestClient,Closeable,AutoCloseable
public final class StitchAuthImpl extends CoreStitchAuth<StitchUser> implements StitchAuth
The Android specific authentication component for clients that acts as aStitchAuthand anStitchAuthRequestClient.
-
-
Constructor Summary
Constructors Constructor Description StitchAuthImpl(StitchRequestClient requestClient, StitchAuthRoutes authRoutes, Storage storage, TaskDispatcher dispatcher, StitchAppClientInfo appInfo)Constructs aStitchAuthImpl.
-
Method Summary
Modifier and Type Method Description voidaddAuthListener(StitchAuthListener listener)Adds a listener for any important auth event.voidaddSynchronousAuthListener(StitchAuthListener listener)protected DocumentgetDeviceInfo()<ClientT> ClientTgetProviderClient(AuthProviderClientFactory<ClientT> factory)Gets a client for the given authentication provider.<T> TgetProviderClient(NamedAuthProviderClientFactory<T> factory, String providerName)Gets a client for the given named authentication provider.protected StitchUserFactory<StitchUser>getUserFactory()Task<StitchUser>loginWithCredential(StitchCredential credential)Logs in as a user with the given credentials associated with an authentication provider.Task<Void>logout()Logs out the active user.Task<Void>logoutUserWithId(String userId)Logs out the user with the provided id.protected voidonActiveUserChanged(StitchUser currentActiveUser, StitchUser previousActiveUser)protected voidonAuthEvent()protected voidonListenerInitialized()protected voidonUserAdded(StitchUser createdUser)protected voidonUserLinked(StitchUser linkedUser)protected voidonUserLoggedIn(StitchUser loggedInUser)protected voidonUserLoggedOut(StitchUser loggedOutUser)protected voidonUserRemoved(StitchUser removedUser)Task<Void>refreshCustomData()You can store arbitrary data about your application users in a MongoDB collection and configure Stitch to automatically expose each user’s data in a field of their user object.voidremoveAuthListener(StitchAuthListener listener)Removes a listener.Task<Void>removeUser()Logs out and removes the active user.Task<Void>removeUserWithId(String userId)Logs out and removes the user with the provided id.-
Methods inherited from class com.mongodb.stitch.core.auth.internal.CoreStitchAuth
close, doAuthenticatedRequest, doAuthenticatedRequest, doAuthenticatedRequest, getAuthRoutes, getDeviceId, getRequestClient, getUser, hasDeviceId, isLoggedIn, isLoggedInInterruptibly, linkUserWithCredentialInternal, listUsers, loginWithCredentialInternal, logoutInternal, logoutUserWithIdInternal, openAuthenticatedStream, refreshAccessToken, removeUserInternal, removeUserWithIdInternal, switchToUserWithId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.mongodb.stitch.android.core.auth.StitchAuth
getUser, isLoggedIn, listUsers, switchToUserWithId
-
-
-
-
Constructor Detail
-
StitchAuthImpl
public StitchAuthImpl(StitchRequestClient requestClient, StitchAuthRoutes authRoutes, Storage storage, TaskDispatcher dispatcher, StitchAppClientInfo appInfo)
Constructs aStitchAuthImpl.- Parameters:
requestClient- the request client to use for any Stitch requests.authRoutes- auth specific routes.storage- where to store/retrieve authentication data.dispatcher- where to send asynchronous requests to.appInfo- information about the application.
-
-
Method Detail
-
getUserFactory
protected StitchUserFactory<StitchUser> getUserFactory()
- Specified by:
getUserFactoryin classCoreStitchAuth<StitchUser>
-
getProviderClient
public <ClientT> ClientT getProviderClient(AuthProviderClientFactory<ClientT> factory)
Description copied from interface:StitchAuthGets a client for the given authentication provider. Most authentication providers will allow creation of a client without a name of the provider.- Specified by:
getProviderClientin interfaceStitchAuth- Type Parameters:
ClientT- The type of client to be returned by the factory.- Parameters:
factory- The factory that will create a client for the authentication provider.- Returns:
- A client to interact with the authentication provider.
-
getProviderClient
public <T> T getProviderClient(NamedAuthProviderClientFactory<T> factory, String providerName)
Description copied from interface:StitchAuthGets a client for the given named authentication provider.- Specified by:
getProviderClientin interfaceStitchAuth- Type Parameters:
T- the type of client to be returned by the factory.- Parameters:
factory- the factory that will create a client for the authentication provider.providerName- the name of the authentication provider.- Returns:
- a client to interact with the authentication provider.
-
loginWithCredential
public Task<StitchUser> loginWithCredential(StitchCredential credential)
Description copied from interface:StitchAuthLogs in as a user with the given credentials associated with an authentication provider.The user who logs in becomes the active user. Other Stitch functionality acts on behalf of the active user. If there was already an active user, that user becomes inactive but still logged in.
- Specified by:
loginWithCredentialin interfaceStitchAuth- Parameters:
credential- the credentials of the user to log in.- Returns:
- a
Taskcontaining user associated with the credentials if log in is successful. - See Also:
StitchAuth.logout(),StitchAuth.logoutUserWithId(java.lang.String),StitchAuth.switchToUserWithId(java.lang.String),StitchAuth.removeUserWithId(java.lang.String)
-
logout
public Task<Void> logout()
Description copied from interface:StitchAuthLogs out the active user.To log out an inactive user, use
StitchAuth.logoutUserWithId(java.lang.String).Except for anonymous users, logged out users remain on the device and will be listed in the result of
StitchAuth.listUsers(). To log in again,StitchAuth.loginWithCredential(com.mongodb.stitch.core.auth.StitchCredential)must be used. To log out and remove the active user, useStitchAuth.removeUser().Anonymous users are deleted immediately after logging out.
- Specified by:
logoutin interfaceStitchAuth- Returns:
- a
Taskcompleting when logged out.
-
logoutUserWithId
public Task<Void> logoutUserWithId(String userId)
Description copied from interface:StitchAuthLogs out the user with the provided id. Throws an exception if the user was not found.Except for anonymous users, logged out users remain on the device and will be listed in the result of
StitchAuth.listUsers(). To log in again,StitchAuth.loginWithCredential(com.mongodb.stitch.core.auth.StitchCredential)must be used. To remove a user from the list, useStitchAuth.removeUserWithId(java.lang.String).Anonymous users are deleted immediately after logging out.
- Specified by:
logoutUserWithIdin interfaceStitchAuth- Parameters:
userId- the id of the user to log out.- Returns:
- a
Taskcompleting when logged out.
-
removeUser
public Task<Void> removeUser()
Description copied from interface:StitchAuthLogs out and removes the active user.To remove an inactive user, see
StitchAuth.removeUserWithId(java.lang.String).Removing a user means removing it from this device, i.e. removing it from the list of users returned by
StitchAuth.listUsers().- Specified by:
removeUserin interfaceStitchAuth- Returns:
- a
Taskcompleting when logged out.
-
removeUserWithId
public Task<Void> removeUserWithId(String userId)
Description copied from interface:StitchAuthLogs out and removes the user with the provided id. Throws an exception if the user was not found.- Specified by:
removeUserWithIdin interfaceStitchAuth- Parameters:
userId- the id of the user to remove.- Returns:
- a
Taskcompleting when logged out.
-
getDeviceInfo
protected Document getDeviceInfo()
- Overrides:
getDeviceInfoin classCoreStitchAuth<StitchUser>
-
addAuthListener
public void addAuthListener(StitchAuthListener listener)
Adds a listener for any important auth event.- Specified by:
addAuthListenerin interfaceStitchAuth- Parameters:
listener- the listener to add.- See Also:
StitchAuthListener
-
addSynchronousAuthListener
public void addSynchronousAuthListener(StitchAuthListener listener)
-
removeAuthListener
public void removeAuthListener(StitchAuthListener listener)
Removes a listener.- Specified by:
removeAuthListenerin interfaceStitchAuth- Parameters:
listener- the listener to remove.- See Also:
StitchAuthListener
-
onAuthEvent
protected void onAuthEvent()
- Specified by:
onAuthEventin classCoreStitchAuth<StitchUser>
-
onListenerInitialized
protected void onListenerInitialized()
- Specified by:
onListenerInitializedin classCoreStitchAuth<StitchUser>
-
onActiveUserChanged
protected void onActiveUserChanged(@Nullable StitchUser currentActiveUser, @Nullable StitchUser previousActiveUser)
- Specified by:
onActiveUserChangedin classCoreStitchAuth<StitchUser>
-
onUserAdded
protected void onUserAdded(StitchUser createdUser)
- Specified by:
onUserAddedin classCoreStitchAuth<StitchUser>
-
onUserLoggedIn
protected void onUserLoggedIn(StitchUser loggedInUser)
- Specified by:
onUserLoggedInin classCoreStitchAuth<StitchUser>
-
onUserRemoved
protected void onUserRemoved(StitchUser removedUser)
- Specified by:
onUserRemovedin classCoreStitchAuth<StitchUser>
-
onUserLoggedOut
protected void onUserLoggedOut(StitchUser loggedOutUser)
- Specified by:
onUserLoggedOutin classCoreStitchAuth<StitchUser>
-
onUserLinked
protected void onUserLinked(StitchUser linkedUser)
- Specified by:
onUserLinkedin classCoreStitchAuth<StitchUser>
-
refreshCustomData
public Task<Void> refreshCustomData()
Description copied from interface:StitchAuthYou can store arbitrary data about your application users in a MongoDB collection and configure Stitch to automatically expose each user’s data in a field of their user object. For example, you might store a user’s preferred language, date of birth, or their local timezone. If this functionality has not been configured, this is a no-op.- Specified by:
refreshCustomDatain interfaceStitchAuth
-
-