Skip to content

Commit

Permalink
Merge pull request #7 from amsametech/bearer-support
Browse files Browse the repository at this point in the history
Bearer support
  • Loading branch information
AmineYagoub authored Aug 8, 2024
2 parents d15c5bc + 30133ec commit 5a9664b
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 93 deletions.
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<a href="https://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
</p>
<p align="center">
<h1 align="center"> Kinde Auth NestJs</h1>
<h1 align="center">Kinde Auth NestJs</h1>

A NestJs Module to validate your [Kinde](https://kinde.com) JSON Web Tokens

Expand All @@ -21,22 +21,12 @@ npm i @amsame/kinde-auth-nestjs
```

- ### Set the environments
kinde supports multi-domain authentication where the primary domain is the same, but there are different NestJs services running in different subdomains.
For example. service1.yourdomain.com, service2.yourdomain.com, so make sure to set this environment in your kinde SDK
To run this module, you will need to set only one environment variable

```bash
KINDE_COOKIE_DOMAIN=.yourdomain.com
```

To run this module, you will need to add the following environment variables to your NestJs .env file

```bash
KINDE_DOMAIN=https://<your-subdomain>.kinde.com
KINDE_AUDIENCE=https://<your-audience>
KINDE_DOMAIN_URL=https://<your-subdomain>.kinde.com
```

make sure you set the audience in your kinde SDK, [see here](docs/audience.md)

- ### Load the module

```ts
Expand Down Expand Up @@ -82,7 +72,7 @@ export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
@KindeRoles(['admin'])
@KindeRoles(['ADMIN'])
hello() {
...
}
Expand All @@ -102,7 +92,7 @@ export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
@KindePermissions(['...', '...'])
@KindePermissions(['YOUR_PERMISSION_HERE', '...'])
hello() {
...
}
Expand All @@ -120,13 +110,33 @@ export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
@KindeIsAuth()
hello(@KindeUser() user: IKindeUser) {
console.log(user)
...
}
}
```

- ### Graphql Resolver

```ts
@Query(() => Post)
async findPostById(
@Args('id', { type: () => Int }) id: number,
@KindeUser() user: IKindeUser,
) {
console.log(id, user);
return ...;
}
```

kinde supports multi-domain authentication where the primary domain is the same, but there are different NestJs services running in different subdomains.
For example. service1.yourdomain.com, service2.yourdomain.com, so make sure to set this environment in your kinde SDK

```bash
KINDE_COOKIE_DOMAIN=.yourdomain.com
```

## License

[MIT](https://choosealicense.com/licenses/mit/)
Loading

0 comments on commit 5a9664b

Please sign in to comment.