Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3 - Create publish workflow #4

Merged
merged 2 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Publish package"

on:
release:
types:
- "published"

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: "Use Node.js"
uses: actions/setup-node@v3
with:
node-version: 14
cache: "npm"
- name: "Install packages"
run: npm install
- name: "Build package"
run: npm run build
- name: "Publish package"
run: npm publish
with:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: "Test package"

on:
pull_request:
branches: [master]
branches:
- "master"
types:
- "opened"
- "synchronize"

jobs:
test:
Expand Down
46 changes: 38 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ NodeJS Auth0 wrapper for Nestjs

## Install
```bash
npm install @twirelab/nestjs-auth0
npm i @twirelab/nestjs-auth0 auth0
npm i -D @types/auth0
```

or

```bash
yarn install @twirelab/nestjs-auth0
yarn add @twirelab/nestjs-auth0 auth0
yarn add -D @types/auth0
```

## Usage

### Authentication Client
## Authentication Client

Add below code into app.module.js file.

```typescript
import { AuthenticationModule } from "@twirelab/nestjs-auth0";

Expand All @@ -36,10 +35,25 @@ import { AuthenticationModule } from "@twirelab/nestjs-auth0";
export class AppModule {}
```

### Management Client
Now you can inject authentication client into your services, for example:
```typescript
import { Injectable } from '@nestjs/common';
import { InjectAuthentication } from "@twirelab/nestjs-auth0";
import { AuthenticationClient, TokenResponse } from "auth0";

@Injectable()
export class AppService {
constructor(@InjectAuthentication() private readonly authentication: AuthenticationClient) { }

async getCredentialsGrant(): Promise<TokenResponse> {
return await this.authentication.clientCredentialsGrant({ audience: "..." });
}
}
```

Add below code into app.module.js file.
## Management Client

Add below code into app.module.js file.
```typescript
import { ManagementModule } from "@twirelab/nestjs-auth0";

Expand All @@ -54,6 +68,22 @@ import { ManagementModule } from "@twirelab/nestjs-auth0";
export class AppModule {}
```

Now you can inject management client into your services, for example:
```typescript
import { Injectable } from "@nestjs/common";
import { InjectManagement } from "@twirelab/nestjs-auth0";
import { ManagementClient, User } from "auth0";

@Injectable()
export class AppService {
constructor(@InjectManagement() private readonly management: ManagementClient) { }

async getUsers(): Promise<User[]> {
return await this.management.getUsers();
}
}
```

To obtain **automatically** a Management API token via the ManagementClient, you can specify the parameters `clientId`, `clientSecret` (use a Non Interactive Client) and optionally `scope`. Behind the scenes the Client Credentials Grant is used to obtain the `access_token` and is by default cached for the duration of the returned `expires_in` value.

```typescript
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "@twirelab/nestjs-auth0",
"version": "0.1.4",
"version": "0.2.0",
"description": "",
"main": "lib/index.js",
"private": false,
"types": "lib/index.d.ts",
"author": "Twirelab",
"author": {
"name": "Twirelab",
"email": "contact@twirelab.com"
},
"license": "MIT",
"scripts": {
"clean": "rimraf lib",
Expand All @@ -28,6 +31,8 @@
"auth0",
"authentication",
"management",
"nodejs",
"express",
"app",
"wrapper",
"client"
Expand Down Expand Up @@ -55,4 +60,4 @@
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0"
}
}
}