Skip to content

Commit

Permalink
Commit enable passing the access token directly into the AuthressClie…
Browse files Browse the repository at this point in the history
…nt class.
  • Loading branch information
wparad committed Dec 28, 2022
1 parent 797ab57 commit 7b9d60b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This is the changelog for [Authress SDK](readme.md).
* Add `Extensions` api
* Upgraded node to 14
* Add support for users and groups at the statement level of access records.
* Enable passing just the access token as a string to `AuthressClient`.

## 1.2 ##
* Removed legacy support for RS512 service client tokens.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const { AuthressClient } = require('authress-sdk');
const { AuthressClient } = require('authress-sdk');

// What is my baseUrl? => API Host: https://authress.io/app/#/api?route=overview
const authressClient = new AuthressClient({ baseUrl: 'https://DOMAIN.api-REGION.authress.io' })
const authressClient = new AuthressClient({ baseUrl: 'https://DOMAIN.api-REGION.authress.io' });

// on api route
[route('/resources/<resourceId>')]
Expand All @@ -52,15 +52,15 @@ async function getResource(resourceId) {
#### Authorize with a service client
```js
const { AuthressClient, ServiceClientTokenProvider } = require('authress-sdk');
const { AuthressClient } = require('authress-sdk');

// create an instance of the API class during service initialization
// Replace DOMAIN with the Authress domain for your account

// Create a service client in the Authress management portal and past the access token here
// This will generate a token automatically instead of passing the user token to the api
const accessToken = 'eyJrZXlJ....';
const authressClient = new AuthressClient({ baseUrl: 'https://DOMAIN.api-REGION.authress.io' }, new ServiceClientTokenProvider(accessToken));
const authressClient = new AuthressClient({ baseUrl: 'https://DOMAIN.api-REGION.authress.io' }, accessToken);

// on api route
[route('/resources/<resourceId>')]
Expand Down
2 changes: 1 addition & 1 deletion examples/expressMicroservice/expressMicroservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const { AuthressClient, ServiceClientTokenProvider, UnauthorizedError } = requir

// Some requests to authress request service client access and cannot use the user's JWT
// IMPORTANT: These should be replace with account specific values
const serviceClientAccessKey = 'eyJrZXlJZCI6IjRkZmM0MDJiLTZmOGUtNGZhNy1iYzM3LWZhMzFlMTVhNmRkYyIsInByaXZhdGVLZXkiOiItLS0tLUJFR0lOIFBSSVZBVEUgS0VZLS0tLS1cbk1JSUV2QUlCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktZd2dnU2lBZ0VBQW9JQkFRQ3IzcUkzSnBQN2tGRHZcbjFnVUl0c2x3V21EV01UbGk3VlRJZEJWNEN2VFpxZHNPNnNWMDFFc1RoOEJBM25QUjJZaUF2UEFuTTlnUTh4bUNcbjZpMzc4eHJUd2RrcS8rU0o5c3ByVkZVeVZxQ0JqKzRSUG1yNllpREgrMFV5Nm10eEI2MzcyaE13Vis0cDAxbDdcbjZSZnRDdWIrVmFOTUxGVTFObWhZRjZFUDNLN1IveklxbHNTemxTWUcwRWprd1ltZjY5RVN0Y2VUcXVkS2tnbGhcbkR3TG5QOGwvWFlCbnV4RDVDQkpXU0tBM0pKaEs0MDhyb2w0U2JpQjZPWFI1Z05ZbCtHakp6ZUt6dkVSUkN6anNcbjE0aUk0NXR0Ty9TaVF1NVJKbThrTDY1ZGc3dUp2dEYrejhZemZpaEtsaGdNSHkwTFVRTXNYZ3ZzVmN1QjhMYUdcbm11bDlZZU9KQWdNQkFBRUNnZ0VBSHc3ZFc0QUNMK3lWWTdIV09Rdm0vUUdvREN6YkJQQ0VhTERwakViV2xscm1cbmRoeWcwQXJwQWo5KzAzb2ZqZVYwa0djVU10RmdremVLL2FoWjVQUzZmVmZEYWN6U1BNZzNMZ3dRVlVkb08rR0pcbmtONHBzTk40dndxK0o0UkxKQ0xTSXZmMmpiN21EL0xjY2RMZWV2eUVYNk9VSGRqSkVST2k2WUJqbjUwdWprMzJcbmx3MEtHOTl2WnRWWmRPY3l6QTYrZG5xMUxWcEtXTEtNeG1uSWVwd2psN3BhbDIzNUI1MnE2dUZQUGZsN1F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CaWxQNldXaWV0aVJcbmJvK0l1aW1BeTFvL0lsK3dYcDZCN1M4YmZZck9IQU91NjQ0VzVua0NnWUJ2WkdJTGRhQWkzYXRoenR0TVJaeFdcbm1oaXYyeXRRU2NIWTlMcVJCMGRYazZOUTkrMEU1MjdraG14Y3dCT1E2UDhrM0RnLyttQTlHWDFyOG15Z3JRTlZcbk9Gb2N2YW90Q2ZyZmdmZTZtRlI1Wm1PM3VRajZIWG42ZGJ3d2srcFEyVTYzMTA4eFRJb0hLd2prQ2xpdWFkTW5cbnFhN2dPUHFZMVA0RHZ2Y2NMSkswQ0E9PVxuLS0tLS1FTkQgUFJJVkFURSBLRVktLS0tLVxuIiwiYXVkaWVuY2UiOiIxMWZmZTk4ZC0xN2ZiLTRlYzktYTVhMi0xYmEyOGZmMmZlMmMuYWNjb3VudHMuYXV0aHJlc3MuaW8iLCJjbGllbnRJZCI6ImU5YWEwMGE4LWE4MzUtNGY4Zi04MzI1LWNiYmEyODUyOGUyMCJ9';
const serviceClientAccessKey = 'eyJrZXlJZCI6IjRkZmM0MDJiLTZmOGUtNGZhNy1iYzM3LWZhMzFlMTVhNmRkYyIsInByaXZhdGVLZXkiOiItLS0tLUJFR0lOIFBSSVZBVE';
const authressDomain = 'https://DOMAIN.api-REGION.authress.io';
const authressServiceClient = new AuthressClient({ baseUrl: authressDomain }, new ServiceClientTokenProvider(serviceClientAccessKey));

Expand Down
5 changes: 2 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1271,10 +1271,9 @@ export class AuthressClient {
* @constructor
* @summary Creates an instance of the Authress client.
* @param {AuthressSettings} settings The authress settings
* @param {Function<string>} [tokenProvider] An optional {@link ServiceClientTokenProvider} which is used to generate an Authress client with the service clients permissions.
* @param {Promise<Function<string>> | Function<string> | string} [tokenProvider] An optional {@link ServiceClientTokenProvider} which is used to generate an Authress client with the service clients permissions.
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
constructor(settings: AuthressSettings, tokenProvider: () => string | ServiceClientTokenProvider);
constructor(settings: AuthressSettings, tokenProvider: (() => Promise<string>) | (() => string) | ServiceClientTokenProvider | string);

/**
* @summary The AccessRecords api
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const RolesApi = require('./src/rolesApi');
const ConnectionsApi = require('./src/connectionsApi');
const ExtensionsApi = require('./src/extensionsApi');
const TenantsApi = require('./src/tenantsApi');
const ServiceClientTokenProvider = require('./src/serviceClientTokenProvider');

class AuthressClient {
constructor(settings, tokenProvider) {
this.settings = settings || {};
this.tokenProvider = tokenProvider;
this.tokenProvider = (tokenProvider && typeof tokenProvider === 'string') ? new ServiceClientTokenProvider(tokenProvider) : tokenProvider;

this.httpClient = new httpClient(this.settings.baseUrl, this.tokenProvider);
this.accessRecords = new AccessRecordsApi(this.httpClient);
Expand All @@ -33,7 +34,6 @@ class AuthressClient {
}
}

const ServiceClientTokenProvider = require('./src/serviceClientTokenProvider');
const TokenVerifier = require('./src/tokenVerifier');
const UnauthorizedError = require('./src/unauthorizedError');
module.exports = { AuthressClient, ServiceClientTokenProvider, UnauthorizedError, TokenVerifier };
Expand Down

0 comments on commit 7b9d60b

Please sign in to comment.