Authentication
@nuclia/core / Authentication
Class: Authentication
Defined in: libs/sdk-core/src/lib/auth/auth.ts:22
It manages authentication to the Nuclia backend. It can be based on login/password for account authentication, or on an API key for private Knowledge Box authentication. Authentication is not necessary when using a public Knowledge Box.
Implements
Constructors
Constructor
new Authentication(
nuclia):Authentication
Defined in: libs/sdk-core/src/lib/auth/auth.ts:27
Parameters
nuclia
Returns
Authentication
Methods
authenticate()
authenticate(
tokens):boolean
Defined in: libs/sdk-core/src/lib/auth/auth.ts:262
Returns a boolean if successful. Stores authentication tokens in localStorage and triggers isAuthenticated.
This method is automatically called when using login and can be useful when using a custom authentication flow.
Example:
nuclia.auth.authenticate(tokens);
Parameters
tokens
Returns
boolean
Implementation of
deleteAuthenticatedUser()
deleteAuthenticatedUser():
Observable<void>
Defined in: libs/sdk-core/src/lib/auth/auth.ts:367
Deletes current user account and removes stored tokens.
Example:
nuclia.auth.deleteAuthenticatedUser().subscribe(() => {
console.log('User deleted');
});
Returns
Observable<void>
Implementation of
IAuthentication.deleteAuthenticatedUser
getAuthHeaders()
Call Signature
getAuthHeaders():
object
Defined in: libs/sdk-core/src/lib/auth/auth.ts:45
Returns the authentication header (which will be Authorization for account authentication, or X-NUCLIA-SERVICEACCOUNT for private Knowledge Box authentication).
Example:
const headers = nuclia.auth.getAuthHeaders();
Returns
object
Implementation of
IAuthentication.getAuthHeaders
Call Signature
getAuthHeaders(
method,path):object
Defined in: libs/sdk-core/src/lib/auth/auth.ts:46
Returns the authentication header (which will be Authorization for account authentication, or X-NUCLIA-SERVICEACCOUNT for private Knowledge Box authentication).
Example:
const headers = nuclia.auth.getAuthHeaders();
Parameters
method
string
path
string
Returns
object
Implementation of
IAuthentication.getAuthHeaders
getAuthInfo()
getAuthInfo(
includeIP?):Observable<AuthInfo>
Defined in: libs/sdk-core/src/lib/auth/auth.ts:387
Returns authentication information
Parameters
includeIP?
boolean = false
Returns
Observable<AuthInfo>
Implementation of
getAuthUrl()
getAuthUrl():
string
Defined in: libs/sdk-core/src/lib/auth/auth.ts:122
Returns
string
Implementation of
getHydraUrl()
getHydraUrl():
string
Defined in: libs/sdk-core/src/lib/auth/auth.ts:126
Returns
string
getJWTUser()
getJWTUser():
JwtUser|null
Defined in: libs/sdk-core/src/lib/auth/auth.ts:400
Parses JWT token and returns corresponding user information.
Example:
const user = nuclia.auth.getJWTUser();
console.log(`Hello ${user?.ext.first_name}!`);
Returns
JwtUser | null
Implementation of
getRefreshToken()
getRefreshToken():
string
Defined in: libs/sdk-core/src/lib/auth/auth.ts:410
Returns refresh token stored in localStorage.
Returns
string
Implementation of
IAuthentication.getRefreshToken
getToken()
getToken(
force?):string
Defined in: libs/sdk-core/src/lib/auth/auth.ts:317
Returns authentication token stored in localStorage.
Parameters
force?
boolean
Returns
string
Implementation of
hasLoggedOut()
hasLoggedOut():
Observable<boolean>
Defined in: libs/sdk-core/src/lib/auth/auth.ts:115
Returns an Observable emitting when the user has logged out.
Example:
nuclia.auth.hasLoggedOut().subscribe((loggedOut) => {
if (loggedOut) {
// do something
}
});
Returns
Observable<boolean>
Implementation of
isAuthenticated()
isAuthenticated():
Observable<boolean>
Defined in: libs/sdk-core/src/lib/auth/auth.ts:99
Emits when the authentication status changes.
Example:
nuclia.auth.isAuthenticated().subscribe((isAuthenticated) => {
if (isAuthenticated) {
console.log('You are authenticated');
} else {
console.log('You are not authenticated');
}
});
Returns
Observable<boolean>
Implementation of
IAuthentication.isAuthenticated
logout()
logout():
void
Defined in: libs/sdk-core/src/lib/auth/auth.ts:274
Calls the logout endpoint and removes the token stored in localStorage.
Returns
void
Implementation of
processAuthorizationResponse()
processAuthorizationResponse(
authCode,returnedState):Observable<{state:any;success:boolean; }>
Defined in: libs/sdk-core/src/lib/auth/auth.ts:176
Parameters
authCode
string
returnedState
string
Returns
Observable<{ state: any; success: boolean; }>
Implementation of
IAuthentication.processAuthorizationResponse
redirectToOAuth()
redirectToOAuth(
queryParams?,oauthUrlParams?):void
Defined in: libs/sdk-core/src/lib/auth/auth.ts:130
Parameters
queryParams?
oauthUrlParams?
Returns
void
Implementation of
IAuthentication.redirectToOAuth
refresh()
refresh():
Observable<boolean>
Defined in: libs/sdk-core/src/lib/auth/auth.ts:290
Returns
Observable<boolean>
requestEmailOtp()
requestEmailOtp():
Observable<void>
Defined in: libs/sdk-core/src/lib/auth/auth.ts:382
Requests an email OTP for the currently authenticated user. Used to verify identity when deleting an account via email-based providers.
Example:
nuclia.auth.requestEmailOtp().subscribe(() => {
console.log('OTP sent');
});
Returns
Observable<void>
Implementation of
IAuthentication.requestEmailOtp
setPassword()
setPassword(
password):Observable<boolean>
Defined in: libs/sdk-core/src/lib/auth/auth.ts:351
Sets the current user’s password.
Example:
nuclia.auth.setPassword(password).subscribe({
next: (success) => {
this.passwordError = success ? '' : 'Error';
console.log('password set', success);
},
error: (error) => {
this.passwordError = 'Error';
console.error(error);
},
complete: () => {
this.pending = false;
},
});
Parameters
password
string
Returns
Observable<boolean>
Implementation of
validateMagicToken()
validateMagicToken(
token,zone?):Observable<MagicAction>
Defined in: libs/sdk-core/src/lib/auth/auth.ts:479
Parameters
token
string
zone?
string
Returns
Observable<MagicAction>