Class ApiKeyAuth


  • public abstract class ApiKeyAuth
    extends Object
    This class exposes functionality for a user to manage API keys under their control.
    • Method Detail

      • getUser

        public User getUser()
        Returns the User that this instance in associated with.
        Returns:
        The User that this instance in associated with.
      • getApp

        public App getApp()
        Returns the App that this instance in associated with.
        Returns:
        The App that this instance in associated with.
      • create

        public ApiKey create​(String name)
                      throws AppException
        Creates a user API key that can be used to authenticate as the user.

        The value of the key must be persisted at this time as this is the only time it is visible.

        The key is enabled when created. It can be disabled by calling disable(ObjectId).

        Parameters:
        name - the name of the key
        Returns:
        the new API key for the user.
        Throws:
        AppException - if the server failed to create the API key.
      • createAsync

        public RealmAsyncTask createAsync​(String name,
                                          App.Callback<ApiKey> callback)
        Asynchronously creates a user API key that can be used to authenticate as the user.

        The value of the key must be persisted at this time as this is the only time it is visible.

        The key is enabled when created. It can be disabled by calling disable(ObjectId).

        Parameters:
        name - the name of the key
        callback - callback when key creation has completed or failed. The callback will always happen on the same thread as this method is called on.
        Throws:
        IllegalStateException - if called from a non-looper thread.
      • fetch

        public ApiKey fetch​(ObjectId id)
                     throws AppException
        Fetches a specific user API key associated with the user.
        Parameters:
        id - the id of the key to fetch.
        Throws:
        AppException - if the server failed to fetch the API key.
      • fetchAsync

        public RealmAsyncTask fetchAsync​(ObjectId id,
                                         App.Callback<ApiKey> callback)
        Fetches a specific user API key associated with the user.
        Parameters:
        id - the id of the key to fetch.
        callback - callback used when the key was fetched or the call failed. The callback will always happen on the same thread as this method was called on.
        Throws:
        IllegalStateException - if called from a non-looper thread.
      • fetchAll

        public List<ApiKey> fetchAll()
                              throws AppException
        Fetches all API keys associated with the user.
        Throws:
        AppException - if the server failed to fetch the API keys.
      • fetchAll

        public RealmAsyncTask fetchAll​(App.Callback<List<ApiKey>> callback)
        Fetches all API keys associated with the user.
        Parameters:
        callback - callback used when the keys were fetched or the call failed. The callback will always happen on the same thread as this method was called on.
        Throws:
        IllegalStateException - if called from a non-looper thread.
      • delete

        public void delete​(ObjectId id)
                    throws AppException
        Deletes a specific API key created by the user.
        Parameters:
        id - the id of the key to delete.
        Throws:
        AppException - if the server failed to delete the API key.
      • deleteAsync

        public RealmAsyncTask deleteAsync​(ObjectId id,
                                          App.Callback<Void> callback)
        Deletes a specific API key created by the user.
        Parameters:
        id - the id of the key to delete.
        callback - callback used when the was deleted or the call failed. The callback will always happen on the same thread as this method was called on.
        Throws:
        IllegalStateException - if called from a non-looper thread.
      • disable

        public void disable​(ObjectId id)
                     throws AppException
        Disables a specific API key created by the user.
        Parameters:
        id - the id of the key to disable.
        Throws:
        AppException - if the server failed to disable the API key.
      • disableAsync

        public RealmAsyncTask disableAsync​(ObjectId id,
                                           App.Callback<Void> callback)
        Disables a specific API key created by the user.
        Parameters:
        id - the id of the key to disable.
        callback - callback used when the key was disabled or the call failed. The callback will always happen on the same thread as this method was called on.
        Throws:
        IllegalStateException - if called from a non-looper thread.
      • enable

        public void enable​(ObjectId id)
                    throws AppException
        Enables a specific API key created by the user.
        Parameters:
        id - the id of the key to enable.
        Throws:
        AppException - if the server failed to enable the API key.
      • enableAsync

        public RealmAsyncTask enableAsync​(ObjectId id,
                                          App.Callback<Void> callback)
        Enables a specific API key created by the user.
        Parameters:
        id - the id of the key to enable.
        callback - callback used when the key was enabled or the call failed. The callback will always happen on the same thread as this method was called on.
        Throws:
        IllegalStateException - if called from a non-looper thread.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object