2020-10-07 09:48:38 +02:00
|
|
|
// Description of the authentication-service
|
|
|
|
// It is listening on port '9004'
|
2020-12-01 16:50:46 +01:00
|
|
|
// Routes with a prefix 'secure' are protected routes, that can only accessed with a valid ticket.
|
|
|
|
// That are routes, that call internally 'authenticate'
|
2020-10-07 09:48:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
// The properties of this interface have to be passed as HTTP-headers in a request.
|
|
|
|
Interface Ticket {
|
|
|
|
authentication: string,
|
|
|
|
cookies: {
|
|
|
|
refreshId: string,
|
|
|
|
[name: string]: string
|
|
|
|
}
|
2020-03-17 13:04:42 +01:00
|
|
|
}
|
|
|
|
|
2020-12-01 16:50:46 +01:00
|
|
|
// This describes, which information is received by requesting `secure/authenticate`.
|
|
|
|
Interface LoginInformation {
|
2020-10-13 11:48:35 +02:00
|
|
|
userId: number;
|
|
|
|
sessionId: string;
|
|
|
|
}
|
|
|
|
|
2020-03-17 13:04:42 +01:00
|
|
|
/**
|
2020-10-07 09:48:38 +02:00
|
|
|
* Describes an http-response, which is sent back to any requesting service.
|
2020-03-17 13:04:42 +01:00
|
|
|
*/
|
2020-10-07 09:48:38 +02:00
|
|
|
Interface Response <T> {
|
2020-12-01 16:50:46 +01:00
|
|
|
set-authentication-header: string // If an old access-token is expired and refreshed, it is set as authentication-header.
|
2020-10-07 09:48:38 +02:00
|
|
|
// This determines if a request was successful.
|
|
|
|
success: boolean,
|
|
|
|
// This sends back a describing message. For example, the reason of a failured request.
|
|
|
|
message: string,
|
|
|
|
// Optional data, which is appended, if a request was successful.
|
|
|
|
data?: T
|
|
|
|
}
|
2020-03-17 13:04:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The credentials for login/authentication are not valid.
|
|
|
|
*/
|
2020-12-01 16:50:46 +01:00
|
|
|
Exception InvalidCredentials {
|
|
|
|
success: false,
|
|
|
|
message: string
|
|
|
|
}
|
2020-03-17 13:04:42 +01:00
|
|
|
|
|
|
|
/**
|
2020-10-07 09:48:38 +02:00
|
|
|
* POST to /system/auth/login
|
|
|
|
*
|
2020-12-01 16:50:46 +01:00
|
|
|
* A user can login with its credentials for authentication.
|
2020-03-17 13:04:42 +01:00
|
|
|
* If they are correct, the service answers with a signed Token and sets a cookie, containing the sessionId of the client.
|
|
|
|
*
|
|
|
|
* If they aren't correct, the service throws an error.
|
|
|
|
*
|
|
|
|
* @throws InvalidCredentials
|
|
|
|
*/
|
2020-10-07 09:48:38 +02:00
|
|
|
login (username: string, password: string): Response<void>;
|
2020-03-17 13:04:42 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-01 16:50:46 +01:00
|
|
|
* POST to /internal/auth/authenticate
|
2020-03-17 13:04:42 +01:00
|
|
|
*
|
|
|
|
* This will be a library to act as part of the auth-service. The other services have not to
|
|
|
|
* request the auth-service for authentication. Instead, they use this library-function in their own
|
|
|
|
* and receive knowledge about authentication without request.
|
|
|
|
*
|
|
|
|
* Throws an exception, if the token is not valid. E.g. if the signature is not valid.
|
|
|
|
*
|
|
|
|
* @throws InvalidCredentials
|
|
|
|
*/
|
2020-12-01 16:50:46 +01:00
|
|
|
authenticate (ticket: Ticket): Response<LoginInformation>;
|
2020-03-17 13:04:42 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-01 16:50:46 +01:00
|
|
|
* POST to /system/auth/who-am-i
|
2020-10-07 09:48:38 +02:00
|
|
|
*
|
2020-03-17 13:04:42 +01:00
|
|
|
* A request to get knowledge about themselves. This information is contained in the payload of
|
|
|
|
* a Token. So, this function handles the refreshing of a Token.
|
2020-12-01 16:50:46 +01:00
|
|
|
* Expects a jwt as string in a cookie (called 'refreshId').
|
2020-03-17 13:04:42 +01:00
|
|
|
*
|
2020-12-01 16:50:46 +01:00
|
|
|
* Sends back a new Token (passed as http-header).
|
2020-03-17 13:04:42 +01:00
|
|
|
*
|
2020-12-01 16:50:46 +01:00
|
|
|
* Throws an exception, if the cookie is empty, the transmitted sessionId is wrong or the signature is wrong.
|
2020-03-17 13:04:42 +01:00
|
|
|
*
|
|
|
|
* @throws InvalidCredentials
|
|
|
|
*/
|
2020-12-01 16:50:46 +01:00
|
|
|
who-am-i (refreshId: string): Response<LoginInformation>;
|
2020-03-17 13:04:42 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-01 16:50:46 +01:00
|
|
|
* POST to /system/auth/secure/clear-session-by-id
|
2020-03-17 13:04:42 +01:00
|
|
|
*
|
2020-10-07 09:48:38 +02:00
|
|
|
* Function to sign out one specific client from a user by its corresponding session-id.
|
2020-03-17 13:04:42 +01:00
|
|
|
*/
|
2020-12-01 16:50:46 +01:00
|
|
|
secure/clear-session-by-id (sessionId: string, ticket: Ticket): Response<void> publishes LogoutSessionEvent;
|
2020-03-17 13:04:42 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-01 16:50:46 +01:00
|
|
|
* POST to /system/auth/secure/clear-all-session-except-themselves
|
2020-03-17 13:04:42 +01:00
|
|
|
*
|
2020-10-07 09:48:38 +02:00
|
|
|
* Function to kill all current opened sessions from one user except the one, which is requesting.
|
2020-03-17 13:04:42 +01:00
|
|
|
*/
|
2020-12-01 16:50:46 +01:00
|
|
|
secure/clear-all-sessions-except-themselves (sessionId: string, ticket: Ticket): Response<void> publishes LogoutSessionEvent;
|
2020-03-17 13:04:42 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-01 16:50:46 +01:00
|
|
|
* POST to /system/auth/secure/logout
|
2020-10-07 09:48:38 +02:00
|
|
|
*
|
2020-03-17 13:04:42 +01:00
|
|
|
* The service deletes the session depending on the given Token.
|
|
|
|
*
|
|
|
|
* @throws InvalidCredentials
|
|
|
|
*/
|
2020-12-01 16:50:46 +01:00
|
|
|
secure/logout (ticket: Ticket): Response<void> publishes LogoutSessionEvent;
|
2020-03-17 13:04:42 +01:00
|
|
|
|
|
|
|
/**
|
2020-12-01 16:50:46 +01:00
|
|
|
* GET to system/auth/secure/list-sessions
|
2020-10-07 09:48:38 +02:00
|
|
|
*
|
2020-03-17 13:04:42 +01:00
|
|
|
* Returns all currently active sessions.
|
|
|
|
*
|
2020-10-07 09:48:38 +02:00
|
|
|
* @returns an array containing currently active sessions.
|
|
|
|
*/
|
2020-12-01 16:50:46 +01:00
|
|
|
secure/list-sessions (ticket: Ticket): Response<{sessions: string[]}>;
|
2020-10-07 09:48:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* POST to /internal/auth/hash
|
|
|
|
*
|
|
|
|
* Hashes a given value. A random salt (64bit) is generated and added to the hashed value.
|
|
|
|
*
|
|
|
|
* @returns the hashed value. The hashed value is structured as follows: [salt + hash].
|
|
|
|
*/
|
|
|
|
hash (toHash: string): Response<{hash: string}>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* POST to /internal/auth/is-equals
|
|
|
|
*
|
|
|
|
* Compares a given value with an given hash.
|
|
|
|
*
|
|
|
|
* @returns a boolean, if the hashed value of the given value is equals to the passed hash.
|
2020-03-17 13:04:42 +01:00
|
|
|
*/
|
2020-10-07 09:48:38 +02:00
|
|
|
is-equals (toHash: string, toCompare: string): Response<{isEquals: boolean}>;
|