CarpAuthService class

The authentication service for CAWS.

Used as a singleton. Must be configured using the configure method before use, like this:

// The authentication configuration
late CarpAuthProperties authProperties = CarpAuthProperties(
  authURL: uri,
  clientId: 'studies-app',
  redirectURI: Uri.parse('carp-studies-auth://auth'),
  // For authentication at CAWS the path is '/auth/realms/Carp'
  discoveryURL: uri.replace(pathSegments: [
    'auth',
    'realms',
    'Carp',
  ]),
);

await CarpAuthService().configure(authProperties);

Basic authentication is using the CAWS login web page, which is opened when calling the authenticate method:

CarpUser user = await CarpAuthService().authenticate();

Constructors

CarpAuthService.new()
Returns the singleton default instance of the CarpAuthService. Before this instance can be used, it must be configured using the configure method.
factory
CarpAuthService.instance()

Properties

authEndpointUri Uri
The URI for the authenticated endpoint for this CarpService.
no setter
authenticated bool
Is a user authenticated? If true, the authenticated user is currentUser.
no setter
authProperties CarpAuthProperties
The CARP authentication properties associated with the CARP Web Service. Returns null if this service has not yet been configured via the configure method.
no setter
authStateChanges Stream<AuthEvent>
Notifies about changes to the user's authentication state (such as sign-in or sign-out) as defined in AuthEvent.
no setter
currentUser CarpUser
Gets the current user. Returns null if no user is authenticated.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isConfigured bool
Has this service been configured?
no setter
manager → OidcUserManager?
The OidcUserManager handling authentication.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

authenticate() Future<CarpUser>
Authenticate to this CARP service. This method will opens the authentication page of the Identity Server using a secure web view from the OS.
authenticateWithUsernamePassword({required String username, required String password}) Future<CarpUser>
Authenticate to this CARP service using a username and password.
configure(CarpAuthProperties authProperties) Future<void>
Configure the this instance of a Carp Service.
getCurrentUserProfile(OidcUser user) CarpUser?
Gets the CARP profile of the current user from the JWT token of user. Returns null if the the user don't have an access token.
initManager() Future<void>
Initialize the manager. This service must be configured before calling this method.
logout() Future<void>
Log out from this CARP service
logoutNoContext() Future<void>
Log out of this CarpService, by clearing the current user.
nonNullAble<T>(T? argument) → T
Makes sure that the CarpApp or CarpUser is configured, by throwing a CarpServiceException if they are null. Otherwise, returns the non-null value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refresh() Future<CarpUser>
Get a new access token for the current user based on the previously granted refresh token, using the Identity Server discovery URL.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited