Skip to content

Commit bf17f2a

Browse files
committed
Generate the loginApi class and export for usage.
1 parent fbf15b7 commit bf17f2a

File tree

13 files changed

+192
-87
lines changed

13 files changed

+192
-87
lines changed

docs/AuthenticationRequest.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# AuthenticationRequest
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**authenticationUrl** | **String** | The recommended next url for the user to navigate to complete the authentication and log in successfully. |

docs/LoginApi.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Login API
2+
3+
Method | HTTP request | Description
4+
------------- | ------------- | -------------
5+
[**updateAuthenticationrequest**](LoginApi.md#updateAuthenticationRequest) | **PATCH** /api/authentication/{authenticationRequestId} | Update authentication request
6+
7+
## updateAuthenticationRequest
8+
9+
> AuthenticationRequest updateAuthenticationRequest(authenticationRequestId, selfHostedLoginApplicationUrl, updateAuthenticationRequestParameters)
10+
11+
Update authentication request
12+
13+
Patch an authentication request and update the properties. Use this to add in a connection ID, tenant ID, or other parameters so the user can complete their authentication and log in. This method should always and only be called from your custom self-hosted login screen: https://authress.io/app/#/settings?focus=branding
14+
15+
### Example
16+
17+
```javascript
18+
import { AuthressClient, Tenant } from '@authress/sdk';
19+
20+
const authenticationRequestId = request.body.state; // AuthenticationRequestId
21+
const updateAuthenticationRequestParameters = new UpdateAuthenticationRequestParameters();
22+
updateAuthenticationRequestParameters.connectionId = 'con_connectionID';
23+
await new AuthressClient().login.updateAuthenticationRequest(authenticationRequestId, selfHostedLoginApplicationUrl, updateAuthenticationRequestParameters);
24+
```
25+
26+
### Parameters
27+
28+
29+
Name | Type | Description | Notes
30+
------------- | ------------- | ------------- | -------------
31+
**authenticationRequestId** | **String**| The ID of the authentication request. When redirected from the Authress authenticate() call, this value is found in the `state` parameter of the url. |
32+
**selfHostedLoginApplicationUrl** | **String**| The application url for the self hosted login screen specified in the advanced options: https://authress.io/app/#/settings?focus=branding. If you are not using a self hosted login screen then this method should not be called. |
33+
**updateAuthenticationRequestParameters** | [**UpdateAuthenticationRequestParameters**](UpdateAuthenticationRequestParameters.md)| | The properties of the authentication request to updated.
34+
35+
### Return type
36+
37+
[**AuthenticationRequest**](AuthenticationRequest.md)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# UpdateAuthenticationRequestParameters
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**connectionId** | **String** | Specify which provider connection that user would like to use to log in - see https://authress.io/app/#/manage?focus=connections | [optional]
8+
**tenantLookupIdentifier** | **String** | Instead of connectionId, specify the tenant lookup identifier to log the user with the mapped tenant - see https://authress.io/app/#/manage?focus=tenants | [optional]
9+
**hint** | **String** | Instead of connectionId or tenant lookup identifier, specify the user's domain or the full email for the user to dynamically identify and log the user with the mapped tenant. | [optional]
10+
**inviteId** | **String** | Invite to use to login, only one of the connectionId, tenantLookupIdentifier, or the inviteId is required. | [optional]
11+
**connectionProperties** | [**ConnectionDefaultConnectionProperties**](ConnectionDefaultConnectionProperties.md) | Overrides the connection specific properties from the Authress Identity Connection to pass to the identity provider | [optional]

index.d.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { Statement, LinkedGroup, User } from './src/records/dtos';
2828
export * from './src/invites/api';
2929
export * from './src/invites/dtos';
3030

31+
import { LoginApi } from './src/login/api';
32+
3133
/**
3234
* The Authress SDK primary settings object to be used with new AuthressClient.
3335
* @export
@@ -986,21 +988,6 @@ export interface UsersApi {
986988
setUserTokenConfiguration(userId: string, tokenConfiguration: UserTokenConfiguration): Promise<Response<void>>;
987989
}
988990

989-
export interface ExtensionAuthenticationParameters {
990-
/** The redirect to your login screen will contain two query parameters `state`. Pass the state into this method. */
991-
state: string;
992-
/** Specify which provider connection that user would like to use to log in - see https://authress.io/app/#/manage?focus=connections */
993-
connectionId?: string;
994-
/** Instead of connectionId, specify the tenant lookup identifier to log the user with the mapped tenant - see https://authress.io/app/#/manage?focus=tenants */
995-
tenantLookupIdentifier?: string;
996-
/** Instead of connectionId or tenant lookup identifier, specify the user's domain or the full email for the user to dynamically identify and log the user with the mapped tenant. */
997-
hint?: string;
998-
/** Invite to use to login, only one of the connectionId, tenantLookupIdentifier, or the inviteId is required. */
999-
inviteId?: string;
1000-
/** Overrides the connection specific properties from the Authress Identity Connection to pass to the identity provider */
1001-
connectionProperties?: Record<string, string>;
1002-
}
1003-
1004991
/**
1005992
* AuthressClient
1006993
* @export
@@ -1089,6 +1076,12 @@ export class AuthressClient {
10891076
*/
10901077
tenants: TenantsApi;
10911078

1079+
/**
1080+
* @summary The Login api
1081+
* @type {LoginApi}
1082+
*/
1083+
login: LoginApi;
1084+
10921085
/**
10931086
* @summary Verify an incoming Authress JWT request access token here.
10941087
* @type {Function<Promise<Record<string, unknown>>>}
@@ -1097,13 +1090,6 @@ export class AuthressClient {
10971090
* @throws {TokenVerificationError}
10981091
*/
10991092
verifyToken(jwtToken: string): Promise<Record<string, unknown>>;
1100-
1101-
/**
1102-
* @description When a platform extension attempts to log a user in, the Authress Login page will redirect to your Platform defaultAuthenticationUrl. At this point, show the user the login screen, and then pass the results of the login to this method.
1103-
* @param {ExtensionAuthenticationParameters} settings Parameters for controlling how and when users should be authenticated for the app.
1104-
* @return {Promise<AuthenticateResponse>} Automatically redirects the user to the appropriate location, unless the connectionId matches a legacy authentication flow.
1105-
*/
1106-
updateExtensionAuthenticationRequest(settings: ExtensionAuthenticationParameters): Promise<AuthenticateResponse>;
11071093
}
11081094

11091095
/**

index.js

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const ExtensionsApi = require('./src/extensionsApi');
1212
const TenantsApi = require('./src/tenantsApi');
1313
const ServiceClientTokenProvider = require('./src/serviceClientTokenProvider');
1414
const TokenVerifier = require('./src/tokenVerifier');
15-
const jwtManager = require('./src/jwtManager');
15+
const LoginApi = require('./src/loginApi');
1616

1717
class AuthressClient {
1818
constructor(settings, tokenProvider) {
@@ -31,6 +31,7 @@ class AuthressClient {
3131
this.connections = new ConnectionsApi(this.httpClient);
3232
this.extensions = new ExtensionsApi(this.httpClient);
3333
this.tenants = new TenantsApi(this.httpClient);
34+
this.login = new LoginApi(this.httpClient);
3435
}
3536

3637
/**
@@ -43,50 +44,6 @@ class AuthressClient {
4344
verifyToken(token) {
4445
return TokenVerifier(this.httpClient, token);
4546
}
46-
47-
/**
48-
* @description When a platform extension attempts to log a user in, the Authress Login page will redirect to your Platform defaultAuthenticationUrl. At this point, show the user the login screen, and then pass the results of the login to this method.
49-
* @param {String} [state] The redirect to your login screen will contain two query parameters `state` and `flow`. Pass the state into this method.
50-
* @param {String} [connectionId] Specify which provider connection that user would like to use to log in - see https://authress.io/app/#/manage?focus=connections
51-
* @param {String} [tenantLookupIdentifier] Instead of connectionId, specify the tenant lookup identifier to log the user with the mapped tenant - see https://authress.io/app/#/manage?focus=tenants
52-
* @param {String} [hint] Instead of connectionId or tenant lookup identifier, specify the user's domain or the full email for the user to dynamically identify and log the user with the mapped tenant.
53-
* @param {Object} [connectionProperties] Connection specific properties to pass to the identity provider. Can be used to override default scopes for example.
54-
* @return {Promise<AuthenticateResponse>} The authentication response.
55-
*/
56-
async updateExtensionAuthenticationRequest({ state, connectionId, tenantLookupIdentifier, connectionProperties, hint }) {
57-
if (!connectionId && !tenantLookupIdentifier && !hint) {
58-
const e = Error('connectionId or tenantLookupIdentifier must be specified');
59-
e.code = 'InvalidConnection';
60-
throw e;
61-
}
62-
63-
const authenticationRequestId = state;
64-
if (!authenticationRequestId) {
65-
const e = Error('The `state` parameters must be specified to update this authentication request');
66-
e.code = 'InvalidAuthenticationRequest';
67-
throw e;
68-
}
69-
70-
try {
71-
const resolvedTenantLookupIdentifier = hint || tenantLookupIdentifier;
72-
const antiAbuseHash = await jwtManager.calculateAntiAbuseHash({ connectionId, tenantLookupIdentifier: resolvedTenantLookupIdentifier, authenticationRequestId });
73-
const requestOptions = await this.httpClient.patch(`/api/authentication/${authenticationRequestId}`, {
74-
antiAbuseHash,
75-
connectionId,
76-
tenantLookupIdentifier: resolvedTenantLookupIdentifier,
77-
connectionProperties
78-
});
79-
80-
return requestOptions.data;
81-
} catch (error) {
82-
if (error.status && error.status >= 400 && error.status < 500) {
83-
const e = Error(error.data && (error.data.title || error.data.errorCode) || error.data || 'Unknown Error');
84-
e.code = error.data && error.data.errorCode;
85-
throw e;
86-
}
87-
throw (error.data || error);
88-
}
89-
}
9047
}
9148

9249
const UnauthorizedError = require('./src/unauthorizedError');

src/connections/api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export interface ConnectionsApi {
1111
* Specify identity connection details for Authress identity aggregation.
1212
* @summary Create SSO connection
1313
* @param {Connection} body
14-
* @throws {RequiredError}
14+
* @throws {ArgumentRequiredError}
1515
*/
1616
createConnection(body: Connection): Promise<Response<Connection>>;
1717

1818
/**
1919
* Delete an identity connection details for Authress identity aggregation.
2020
* @summary Delete SSO connection
2121
* @param {string} connectionId The connection identifier.
22-
* @throws {RequiredError}
22+
* @throws {ArgumentRequiredError}
2323
*/
2424
deleteConnection(connectionId: string): Promise<Response<void>>;
2525

@@ -28,22 +28,22 @@ export interface ConnectionsApi {
2828
* @summary Update SSO connection
2929
* @param {Connection} body
3030
* @param {string} connectionId The connection identifier.
31-
* @throws {RequiredError}
31+
* @throws {ArgumentRequiredError}
3232
*/
3333
updateConnection(connectionId: string, body: Connection): Promise<Response<Connection>>;
3434

3535
/**
3636
* Get the identity connection details for Authress identity aggregation.
3737
* @summary Retrieve SSO connection
3838
* @param {string} connectionId The connection identifier.
39-
* @throws {RequiredError}
39+
* @throws {ArgumentRequiredError}
4040
*/
4141
getConnection(connectionId: string): Promise<Response<Connection>>;
4242

4343
/**
4444
* Returns a paginated connection list for the account. Only connections the user has access to are returned.
4545
* @summary List SSO connections
46-
* @throws {RequiredError}
46+
* @throws {ArgumentRequiredError}
4747
*/
4848
getConnections(): Promise<Response<ConnectionCollection>>;
4949

src/extensions/api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export interface ExtensionsApi {
1111
* Specify identity extension details for Authress identity aggregation.
1212
* @summary Create SSO extension
1313
* @param {Extension} body
14-
* @throws {RequiredError}
14+
* @throws {ArgumentRequiredError}
1515
*/
1616
createExtension(body: Extension): Promise<Response<Extension>>;
1717

1818
/**
1919
* Delete an identity extension details for Authress identity aggregation.
2020
* @summary Delete SSO extension
2121
* @param {string} extensionId The extension identifier.
22-
* @throws {RequiredError}
22+
* @throws {ArgumentRequiredError}
2323
*/
2424
deleteExtension(extensionId: string): Promise<Response<void>>;
2525

@@ -28,22 +28,22 @@ export interface ExtensionsApi {
2828
* @summary Update SSO extension
2929
* @param {Extension} body
3030
* @param {string} extensionId The extension identifier.
31-
* @throws {RequiredError}
31+
* @throws {ArgumentRequiredError}
3232
*/
3333
updateExtension(extensionId: string, body: Extension): Promise<Response<Extension>>;
3434

3535
/**
3636
* Get the identity extension details for Authress identity aggregation.
3737
* @summary Retrieve SSO extension
3838
* @param {string} extensionId The extension identifier.
39-
* @throws {RequiredError}
39+
* @throws {ArgumentRequiredError}
4040
*/
4141
getExtension(extensionId: string): Promise<Response<Extension>>;
4242

4343
/**
4444
* Returns a paginated extension list for the account. Only extensions the user has access to are returned.
4545
* @summary List SSO extensions
46-
* @throws {RequiredError}
46+
* @throws {ArgumentRequiredError}
4747
*/
4848
getExtensions(): Promise<Response<ExtensionCollection>>;
4949
}

src/invites/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface InvitesApi {
2626
* Accepts an invite by claiming this invite by this user. The user access token used for this request will gain the permissions associated with the invite.
2727
* @summary Accept invite
2828
* @param {string} inviteId The identifier of the invite.
29-
* @throws {RequiredError}
29+
* @throws {ArgumentRequiredError}
3030
*/
3131
respondToInvite(inviteId: string): Promise<Response<void>>;
3232
/**

src/jwtManager.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ class JwtManager {
1010
}
1111
}
1212

13-
async calculateAntiAbuseHash(props) {
13+
calculateAntiAbuseHash(props) {
1414
const timestamp = Date.now();
1515
const valueString = Object.values(props).filter(v => v).join('|');
1616

1717
let fineTuner = 0;
1818
let hash = null;
1919
while (++fineTuner) {
20-
hash = base64url.encode(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(`${timestamp};${fineTuner};${valueString}`)));
20+
const verifier = `${timestamp};${fineTuner};${valueString}`;
21+
hash = base64url.encode(crypto.createHash('sha256').update(verifier).digest());
2122
if (hash.match(/^00/)) {
22-
break;
23+
return `v2;${verifier}`;
2324
}
2425
}
2526

26-
return `v2;${timestamp};${fineTuner};${hash}`;
27+
throw Error('Could not calculate a valid anti abuse hash.');
2728
}
2829
}
2930

src/login/api.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable node/no-missing-import */
2+
import { Response } from '../response';
3+
import { UpdateAuthenticationRequestParameters, AuthenticationRequest } from './dtos';
4+
5+
/**
6+
* LoginApi
7+
* @export
8+
*/
9+
export interface LoginApi {
10+
/**
11+
* Patch an authentication request and update the properties. Use this to add in a connection ID, tenant ID, or other parameters so the user can complete their authentication and log in. This method should always and only be called from your custom self-hosted login screen: https://authress.io/app/#/settings?focus=branding
12+
* @summary Update Authentication Request
13+
* @param {string} authenticationRequestId The ID of the authentication request. When redirected from the Authress authenticate() call, this value is found in the `state` parameter of the url.
14+
* @param {string} selfHostedLoginApplicationUrl The application url for the self hosted login screen specified in the advanced options: https://authress.io/app/#/settings?focus=branding. If you are not using a self hosted login screen then this method should not be called.
15+
* @param {UpdateAuthenticationRequestParameters} authenticationRequest The properties of the authentication request to updated.
16+
* @throws {ArgumentRequiredError}
17+
*/
18+
updateAuthenticationRequest(authenticationRequestId: string, selfHostedLoginApplicationUrl: string, authenticationRequest: UpdateAuthenticationRequestParameters):
19+
Promise<Response<AuthenticationRequest>>;
20+
}

0 commit comments

Comments
 (0)