Skip to content

Commit

Permalink
Merge pull request #159 from frontegg/next
Browse files Browse the repository at this point in the history
Entitlements deployment
  • Loading branch information
eran-frontegg authored Jul 30, 2023
2 parents 7927df4 + 4efcf23 commit c5a209d
Show file tree
Hide file tree
Showing 30 changed files with 3,507 additions and 17,485 deletions.
82 changes: 73 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
<li><a href="#usage">Usage</a></li>
</ul>

## Notice

### Version 3.0.0 is Deprecated. Please use versions 4.x.x

### If you are upgrading from version 2.x.x skip version 3.0.0 by installing the latest version

---

## Breaking Changes

* ### As of version 3.0.0 and 4.0.0, we will no longer provide proxy middlewares
Expand Down Expand Up @@ -192,6 +184,78 @@ const { data, total } = await audits.getAudits({
});
```

### Entitlements Client

#### Initializing the client
```javascript

const { EntitlementsClient } = require('@frontegg/client');

// initialize the FronteggContext
FronteggContext.init(
{
FRONTEGG_CLIENT_ID: '<YOUR_CLIENT_ID>',
FRONTEGG_API_KEY: '<YOUR_API_KEY>',
},
{
accessTokensOptions,
},
);

// initialize entitlements client
const client = await EntitlementsClient.init(/* */);
await client.ready();
```

#### Using the client
The client can be used to determine if authorized user or tenant is entitled to particular feature or permission.

First, we need to validate its token, using the `IdentityClient`:
```javascript
// validate token and decode its properties
const userOrTenantEntity = await identityClient.validateToken(token, { withRolesAndPermissions: true });
```
> Note, that some JWT tokens might not contain permissions stored in their payloads. Permissions are essential for
> entitlement decision-making, so remember to add option flag: `withRolesAndPermissions: true`.
(see <a href="#validating-jwt-manually">Validating JWT manually</a> section for more details).

When the user/tenant entity is resolved, you can start querying the entitlements engine:
```javascript
const userEntitlementsClient = client.forUser(userOrTenantEntity);

let result;

// asking for feature entitlement
result = await userEntitlementsClient.isEntitledToFeature('foo');
// or
result = await userEntitlementsClient.isEntitledTo({
featureKey: 'foo'
});

// asking for permission entitlement
result = await userEntitlementsClient.isEntitledToPermission('foo.read');
// or
result = await userEntitlementsClient.isEntitledTo({
permissionKey: 'foo'
});
```

The result of those queries has the following structure:
```typescript
type IsEntitledResult = {
result: boolean,
justficiation?: string
}
```
When `result: true`, then `justficiation` is not given.
#### Closing the client
To gracefully close the client:
```javascript
client.destroy();
```

### Working with the REST API

Frontegg provides a comprehensive REST API for your application.
Expand All @@ -218,7 +282,7 @@ await httpClient.post(
);
```

### Validating JWT manually
### <a name="validating-jwt-manually"></a>Validating JWT manually

If required you can implement your own middleware which will validate the Frontegg JWT using the `IdentityClient`

Expand Down
21 changes: 21 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# [5.1.0-alpha.3](https://github.com/frontegg/nodejs-sdk/compare/5.1.0-alpha.2...5.1.0-alpha.3) (2023-07-25)


### Bug Fixes

* **entitlements:** rename reason to justification ([a437b84](https://github.com/frontegg/nodejs-sdk/commit/a437b84213ebffbe17590f898cb0d6908869121a))

# [5.1.0-alpha.2](https://github.com/frontegg/nodejs-sdk/compare/5.1.0-alpha.1...5.1.0-alpha.2) (2023-07-21)


### Bug Fixes

* **entitlements:** fixed the way of fetching user ID ([6df03ac](https://github.com/frontegg/nodejs-sdk/commit/6df03ac156434b4eab1e76126a8766f36360fd03))

# [5.1.0-alpha.1](https://github.com/frontegg/nodejs-sdk/compare/5.0.0...5.1.0-alpha.1) (2023-07-17)


### Features

* **entitlements:** add support for entitlements ([ce857c9](https://github.com/frontegg/nodejs-sdk/commit/ce857c96c1359e5e6aa39c6a7986b1704ca44b50))

# [5.0.0](https://github.com/frontegg/nodejs-sdk/compare/4.2.2...5.0.0) (2023-06-21)


Expand Down
12 changes: 10 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { FronteggAuthenticator } from './src/authenticator';
import { FronteggContext } from './src/components/frontegg-context';
import { withAuthentication } from './src/middlewares';
import { AuditsClient, HttpClient, IdentityClient } from './src/clients';
import { AuditsClient, HttpClient, IdentityClient, EntitlementsClient } from './src/clients';

export { AuditsClient, FronteggContext, FronteggAuthenticator, withAuthentication, HttpClient, IdentityClient };
export {
AuditsClient,
FronteggContext,
FronteggAuthenticator,
withAuthentication,
HttpClient,
IdentityClient,
EntitlementsClient,
};
export * from './src/clients/hosted-login';
Loading

0 comments on commit c5a209d

Please sign in to comment.