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 aStitchAuth
and 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 void
addAuthListener(StitchAuthListener listener)
Adds a listener for any important auth event.void
addSynchronousAuthListener(StitchAuthListener listener)
protected Document
getDeviceInfo()
<ClientT> ClientT
getProviderClient(AuthProviderClientFactory<ClientT> factory)
Gets a client for the given authentication provider.<T> T
getProviderClient(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 void
onActiveUserChanged(StitchUser currentActiveUser, StitchUser previousActiveUser)
protected void
onAuthEvent()
protected void
onListenerInitialized()
protected void
onUserAdded(StitchUser createdUser)
protected void
onUserLinked(StitchUser linkedUser)
protected void
onUserLoggedIn(StitchUser loggedInUser)
protected void
onUserLoggedOut(StitchUser loggedOutUser)
protected void
onUserRemoved(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.void
removeAuthListener(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:
getUserFactory
in classCoreStitchAuth<StitchUser>
-
getProviderClient
public <ClientT> ClientT getProviderClient(AuthProviderClientFactory<ClientT> factory)
Description copied from interface:StitchAuth
Gets a client for the given authentication provider. Most authentication providers will allow creation of a client without a name of the provider.- Specified by:
getProviderClient
in 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:StitchAuth
Gets a client for the given named authentication provider.- Specified by:
getProviderClient
in 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:StitchAuth
Logs 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:
loginWithCredential
in interfaceStitchAuth
- Parameters:
credential
- the credentials of the user to log in.- Returns:
- a
Task
containing 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:StitchAuth
Logs 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:
logout
in interfaceStitchAuth
- Returns:
- a
Task
completing when logged out.
-
logoutUserWithId
public Task<Void> logoutUserWithId(String userId)
Description copied from interface:StitchAuth
Logs 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:
logoutUserWithId
in interfaceStitchAuth
- Parameters:
userId
- the id of the user to log out.- Returns:
- a
Task
completing when logged out.
-
removeUser
public Task<Void> removeUser()
Description copied from interface:StitchAuth
Logs 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:
removeUser
in interfaceStitchAuth
- Returns:
- a
Task
completing when logged out.
-
removeUserWithId
public Task<Void> removeUserWithId(String userId)
Description copied from interface:StitchAuth
Logs out and removes the user with the provided id. Throws an exception if the user was not found.- Specified by:
removeUserWithId
in interfaceStitchAuth
- Parameters:
userId
- the id of the user to remove.- Returns:
- a
Task
completing when logged out.
-
getDeviceInfo
protected Document getDeviceInfo()
- Overrides:
getDeviceInfo
in classCoreStitchAuth<StitchUser>
-
addAuthListener
public void addAuthListener(StitchAuthListener listener)
Adds a listener for any important auth event.- Specified by:
addAuthListener
in 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:
removeAuthListener
in interfaceStitchAuth
- Parameters:
listener
- the listener to remove.- See Also:
StitchAuthListener
-
onAuthEvent
protected void onAuthEvent()
- Specified by:
onAuthEvent
in classCoreStitchAuth<StitchUser>
-
onListenerInitialized
protected void onListenerInitialized()
- Specified by:
onListenerInitialized
in classCoreStitchAuth<StitchUser>
-
onActiveUserChanged
protected void onActiveUserChanged(@Nullable StitchUser currentActiveUser, @Nullable StitchUser previousActiveUser)
- Specified by:
onActiveUserChanged
in classCoreStitchAuth<StitchUser>
-
onUserAdded
protected void onUserAdded(StitchUser createdUser)
- Specified by:
onUserAdded
in classCoreStitchAuth<StitchUser>
-
onUserLoggedIn
protected void onUserLoggedIn(StitchUser loggedInUser)
- Specified by:
onUserLoggedIn
in classCoreStitchAuth<StitchUser>
-
onUserRemoved
protected void onUserRemoved(StitchUser removedUser)
- Specified by:
onUserRemoved
in classCoreStitchAuth<StitchUser>
-
onUserLoggedOut
protected void onUserLoggedOut(StitchUser loggedOutUser)
- Specified by:
onUserLoggedOut
in classCoreStitchAuth<StitchUser>
-
onUserLinked
protected void onUserLinked(StitchUser linkedUser)
- Specified by:
onUserLinked
in classCoreStitchAuth<StitchUser>
-
refreshCustomData
public Task<Void> refreshCustomData()
Description copied from interface:StitchAuth
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. 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:
refreshCustomData
in interfaceStitchAuth
-
-