Interface StitchAuth

  • All Known Implementing Classes:
    StitchAuthImpl

    public interface StitchAuth
    StitchAuth manages authentication for any Stitch based client. It provides methods for logging in with various authentication providers using StitchCredentials, retrieving the current user, and getting authentication provider clients to perform actions such as registering users and creating user API keys.
    • Method Detail

      • getProviderClient

        <ClientT> ClientT getProviderClient​(AuthProviderClientFactory<ClientT> factory)
        Gets a client for the given authentication provider. Most authentication providers will allow creation of a client without a name of the provider.
        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

        <T> T getProviderClient​(NamedAuthProviderClientFactory<T> factory,
                                String providerName)
        Gets a client for the given named authentication provider.
        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.
      • logout

        void logout()
        Logs out the currently logged in, active user. Switches to the next logged in user if there is another.
      • logoutUserWithId

        void logoutUserWithId​(String userId)
                       throws IllegalArgumentException
        Logs out the a user with the provided id. Throws an exception if the user was not found.
        Parameters:
        userId - the id of the user to logoutUserWithId
        Throws:
        IllegalArgumentException - throws if user id not found
      • removeUser

        void removeUser()
        Logs out and removes the currently logged in, active user. Switches to the next logged in user if there is another.
      • removeUserWithId

        void removeUserWithId​(String userId)
        Logs out and removes the a user with the provided id. Throws an exception if the user was not found.
        Parameters:
        userId - the id of the user to remove
      • isLoggedIn

        boolean isLoggedIn()
        Returns whether or not there's a currently logged in user.
        Returns:
        whether or not there's a currently logged in user.
      • getUser

        @Nullable
        StitchUser getUser()
        Returns the currently logged in, active user; null if no users are logged in.
        Returns:
        the currently logged in, active user; null if no users are logged in.
      • listUsers

        List<StitchUser> listUsers()
        Returns a set of all logged in users.
        Returns:
        the set of currently logged in users
      • switchToUserWithId

        StitchUser switchToUserWithId​(String userId)
                               throws IllegalArgumentException
        Switches the active user to the user with the provided id. Throws an exception if the user was not found.
        Parameters:
        userId - the id of the user to switch to
        Returns:
        the user that was switched to
        Throws:
        IllegalArgumentException - throws if user id not found
      • addAuthListener

        void addAuthListener​(StitchAuthListener listener)
        Adds a listener for any important auth event.
        Parameters:
        listener - the listener to add.
        See Also:
        StitchAuthListener
      • removeAuthListener

        void removeAuthListener​(StitchAuthListener listener)
        Removes a listener.
        Parameters:
        listener - the listener to remove.
      • refreshCustomData

        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. 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.