Interface IAuthentication

All Known Subinterfaces:
ISagaDefaultAuthentication, ITokenAuthentication

public interface IAuthentication
Implement the authentication flow to authenticate users in Saga. This class will be used on every protected endpoint.

This class will be instantiated very early, to allow for it to add additional space-level configurations.

Because of this it is EXTREMELY IMPORTANT that any injected dependencies are either without side effects, such as configuration files, or are injected as a Provider to avoid any potential issues with the instantiation order of the class.

You can use IAuthenticationSession to manage sessions. Otherwise, You can also use your own session manager.

With the method authenticate(IAuthenticationRequest, IAuthenticationResponse, IAuthenticationSession) you can create your own authentication.

In case you are using 3rd party authentication providers you can use this method to integrate with them.

To create a valid authentication you need to provide a user with a valid role, otherwise Saga will assume that the user doesn't have any permissions.

You can also manage the signout of a user by implementing the method signOut(IAuthenticationRequest, IAuthenticationResponse, IAuthenticationSession).

Here, if you are using Saga session manager, you are advised to invalidate the session $IAuthenticationSession.invalidate().

Register your implementation using api().authentication() in the ioc-interface.

See Also:
  • Method Details

    • authenticate

      Implementation of the custom authentication. This method will be called for every request made to protected endpoints, and when logging in using Saga UI.
      Parameters:
      req - authentication request
      resp - authentication response
      session - saga session manager
      Returns:
      authenticate user
    • signOut

      Implementation of the custom sign out.
      Parameters:
      req - authentication request
      resp - authentication response
      session - saga session manager
    • configureUserMenu

      void configureUserMenu(IContextMenu userMenu, User loggedInUser)
      Will be invoked by Saga Core when the Saga UI is to be rendered to allow the authentication implementation a way to manipulate the top right corner user menu.
      Parameters:
      userMenu - the user menu to manipulate
      loggedInUser - the user currently logged in
    • configureIntoSpace

      void configureIntoSpace(ISpaceExtensionPointIoc spacesIoc)
      Will be invoked by Saga Core when the space is done configuring and the authentication implementation is known to allow the authentication implementation a way to manipulate the space configuration.

      This is used to add pages and API endpoints needed for the authentication implementation, as normally modules can only configure into the core space unless explicitly configured in the solution configuration.

      This will be called exactly once for each space the authentication implementation is configured into, including the core space, if applicable.

      Parameters:
      spacesIoc - the space configuration
    • getUsers

      default List<User> getUsers(@Nonnull Class<? extends SpaceExtensionContext> space)
      Get all users in the space.
      Parameters:
      space - the space to get users from
      Returns:
      list of users