A suite of libraries to make NestJS and Ory fall in love
Installations
npm install @getlarge/hydra-client-wrapper
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
20.11.0
NPM Version
10.9.0
Score
69.4
Supply Chain
98
Quality
79.3
Maintenance
100
Vulnerability
100
License
Releases
keto-cli@0.2.9
Published on 01 Feb 2025
keto-client-wrapper@0.6.0
Published on 01 Feb 2025
keto-cli@0.2.8
Published on 12 Nov 2024
keto-client-wrapper@0.5.0
Published on 12 Nov 2024
keto-cli@0.2.7
Published on 06 Nov 2024
keto-client-wrapper@0.4.0
Published on 06 Nov 2024
Contributors
Languages
TypeScript (94.08%)
JavaScript (5.52%)
Dockerfile (0.4%)
Developer
getlarge
Download Statistics
Total Downloads
3,140
Last Day
2
Last Week
82
Last Month
272
Last Year
3,140
GitHub Statistics
15 Stars
215 Commits
1 Watching
10 Branches
1 Contributors
Bundle Size
23.20 kB
Minified
6.30 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.3.1
Package Id
@getlarge/hydra-client-wrapper@0.3.1
Unpacked Size
53.78 kB
Size
11.44 kB
File Count
49
NPM Version
10.9.0
Node Version
20.11.0
Publised On
07 Oct 2024
Total Downloads
Cumulative downloads
Total Downloads
3,140
Last day
-90.5%
2
Compared to previous day
Last week
-18.8%
82
Compared to previous week
Last month
130.5%
272
Compared to previous month
Last year
0%
3,140
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
4
hydra-client-wrapper
This library is a wrapper around the Ory Hydra client - @ory/client. It provides :
OryOidcModule
: a module to interact with the Ory Hydra Oidc (public) APIOryOAuth2Module
: a module to interact with the Ory Hydra OAuth2 (admin) API
Install
1npm install @getlarge/hydra-client-wrapper
Usage
Import the module in your app:
1import { 2 OryIdentitiesModule, 3 OryFrontendModule, 4} from '@getlarge/kratos-client-wrapper'; 5import { Module } from '@nestjs/common'; 6 7@Module({ 8 imports: [ 9 OryIdentitiesModule.forRoot({ 10 basePath: 'http://localhost:4434', 11 accessToken: 'my-access-token', 12 }), 13 OryFrontendModule.forRootAsync({ 14 useFactory: () => ({ 15 baseUrl: 'http://localhost:4433', 16 }), 17 }), 18 ], 19}) 20export class YourModule {}
Inject the service in your provider:
1import { OryOAuth2Service } from '@getlarge/hydra-client-wrapper'; 2import { Injectable } from '@nestjs/common'; 3 4@Injectable() 5export class YourService { 6 constructor(private readonly oryOAuth2Service: OryOAuth2Service) {} 7 8 async createClient(ownerId: string, scope = 'offline') { 9 return this.oryOAuth2Service.createOAuth2Client({ 10 oAuth2Client: { 11 grant_types: ['client_credentials'], 12 access_token_strategy: 'opaque', 13 owner: ownerId, 14 scope, 15 }, 16 }); 17 } 18}
Use the Guard to protect your routes:
1import { OryOAuth2AuthenticationGuard } from '@getlarge/hydra-client-wrapper'; 2import { Controller, Get, Logger, UseGuards } from '@nestjs/common'; 3 4@Controller() 5export class YourController { 6 @UseGuards( 7 OryOAuth2AuthenticationGuard({ 8 async postValidationHook(ctx, token) { 9 const req = ctx.switchToHttp().getRequest(); 10 if (!token.client_id) { 11 throw new Error('Client ID not found in token'); 12 } 13 const { data: client } = await this.oryService.getOAuth2Client({ 14 id: token.client_id, 15 }); 16 req.client = client; 17 }, 18 accessTokenResolver: (ctx) => 19 ctx 20 .switchToHttp() 21 .getRequest() 22 ?.headers?.authorization?.replace('Bearer ', ''), 23 }) 24 ) 25 @Get() 26 async get() { 27 return 'Hello World'; 28 } 29}
Development
Building
Run nx build hydra-client-wrapper
to build the library.
Running unit tests
Run nx test hydra-client-wrapper
to execute the unit tests via Jest.
No vulnerabilities found.
No security vulnerabilities found.