Skip to content

Commit d46d7fc

Browse files
authored
Merge pull request #61 from cranberyxl/feature/updateExtensionAuthenticationRequest
port updateExtensionAuthenticationRequest
2 parents 7e94b95 + bf17f2a commit d46d7fc

File tree

13 files changed

+205
-16
lines changed

13 files changed

+205
-16
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 & 0 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
@@ -1082,6 +1084,12 @@ export class AuthressClient {
10821084
*/
10831085
tenants: TenantsApi;
10841086

1087+
/**
1088+
* @summary The Login api
1089+
* @type {LoginApi}
1090+
*/
1091+
login: LoginApi;
1092+
10851093
/**
10861094
* @summary Verify an incoming Authress JWT request access token here.
10871095
* @type {Function<Promise<Record<string, unknown>>>}

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +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 LoginApi = require('./src/loginApi');
1516

1617
class AuthressClient {
1718
constructor(settings, tokenProvider) {
@@ -30,6 +31,7 @@ class AuthressClient {
3031
this.connections = new ConnectionsApi(this.httpClient);
3132
this.extensions = new ExtensionsApi(this.httpClient);
3233
this.tenants = new TenantsApi(this.httpClient);
34+
this.login = new LoginApi(this.httpClient);
3335
}
3436

3537
/**

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const base64url = require('base64url');
2+
const crypto = require('crypto');
23

34
class JwtManager {
45
decode(token) {
@@ -8,6 +9,23 @@ class JwtManager {
89
return null;
910
}
1011
}
12+
13+
calculateAntiAbuseHash(props) {
14+
const timestamp = Date.now();
15+
const valueString = Object.values(props).filter(v => v).join('|');
16+
17+
let fineTuner = 0;
18+
let hash = null;
19+
while (++fineTuner) {
20+
const verifier = `${timestamp};${fineTuner};${valueString}`;
21+
hash = base64url.encode(crypto.createHash('sha256').update(verifier).digest());
22+
if (hash.match(/^00/)) {
23+
return `v2;${verifier}`;
24+
}
25+
}
26+
27+
throw Error('Could not calculate a valid anti abuse hash.');
28+
}
1129
}
1230

1331
module.exports = new JwtManager();

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)