Gathering detailed insights and metrics for @envelop/auth0
Gathering detailed insights and metrics for @envelop/auth0
Envelop is a lightweight library allowing developers to easily develop, share, collaborate and extend their GraphQL execution layer. Envelop is the missing GraphQL plugin system.
npm install @envelop/auth0
Typescript
Module System
Min. Node Version
Node Version
NPM Version
81.8
Supply Chain
98.3
Quality
93.9
Maintenance
100
Vulnerability
98.2
License
January 27, 2025
Updated on Jan 27, 2025
January 16, 2025
Updated on Jan 16, 2025
January 13, 2025
Updated on Jan 13, 2025
December 12, 2024
Updated on Dec 12, 2024
December 11, 2024
Updated on Dec 11, 2024
November 26, 2024
Updated on Nov 26, 2024
TypeScript (69.4%)
MDX (29.04%)
JavaScript (1.56%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
554,155
Last Day
138
Last Week
3,900
Last Month
16,053
Last Year
205,529
MIT License
801 Stars
1,900 Commits
130 Forks
10 Watchers
72 Branches
78 Contributors
Updated on Feb 15, 2025
Minified
Minified + Gzipped
Latest Version
6.0.0
Package Id
@envelop/auth0@6.0.0
Unpacked Size
17.16 kB
Size
4.87 kB
File Count
8
NPM Version
10.1.0
Node Version
20.8.0
Published on
Oct 16, 2023
Cumulative downloads
Total Downloads
Last Day
245%
138
Compared to previous day
Last Week
-30.5%
3,900
Compared to previous week
Last Month
62.7%
16,053
Compared to previous month
Last Year
-15.4%
205,529
Compared to previous year
3
1
@envelop/auth0
This plugin validates an JWT token created by Auth0, and injects the Auth0 user properties into your GraphQL context. With this plugin, you can implement authentication and authorization in a simple way.
The plugins is using JWKS standard in order to validate the token.
We recommend using the Adding Authentication with Auth0 guide if this is your first time using this plugin!
Authorization: Bearer XYZ
). You can find more info here:
https://auth0.com/docs/quickstart/spaaudience
and domain
configurations.1import { execute, parse, specifiedRules, subscribe, validate } from 'graphql' 2import { useAuth0 } from '@envelop/auth0' 3import { envelop, useEngine } from '@envelop/core' 4 5const getEnveloped = envelop({ 6 plugins: [ 7 useEngine({ parse, validate, specifiedRules, execute, subscribe }), 8 // ... other plugins ... 9 useAuth0({ 10 onError: e => {}, // In case of an error, you can override it and customize the error your client will get. 11 domain: 'YOUR_AUTH0_DOMAIN_HERE', 12 audience: 'YOUR_AUTH0_AUDIENCE_HERE', 13 headerName: 'authorization', // Name of the header 14 preventUnauthenticatedAccess: true, // If you need to have unauthenticated parts on your schema, make sure to disable that by setting it to `false` and the check it in your resolvers. 15 extendContextField: 'auth0', // The name of the field injected to your `context` 16 tokenType: 'Bearer' // Type of token to expect in the header 17 }) 18 ] 19})
1myHttpServer.on('request', async req => { 2 const { contextFactory } = getEnveloped({ req }) 3 const contextValue = await contextFactory({ req }) // Make sure to pass it here 4})
By default, this plugins looks for
req
orrequest
properties in your base context. If you need to override it, please useextractTokenFn
and you can customize it.
sub
) as part of your context
during execution:1const myResolvers = { 2 Query: { 3 me: (root, args, context, info) => { 4 const auth0UserId = context.auth0.sub 5 } 6 } 7}
jwksClientOptions
Pass this to customize the JWKS client creation. See: https://github.com/auth0/node-jwks-rsa
Setting this will override any other options defined by this plugin.
jwtDecodeOptions
Pass this to customize the JWT decode
phase. See:
https://www.npmjs.com/package/jws#jwsdecodesignature
jwtVerifyOptions
Pass this to customize the JWT verify
phase. See:
https://github.com/auth0/node-jsonwebtoken#jwtverifytoken-secretorpublickey-options-callback
onError(e: Error)
By default, this library will throw an error during context building if an error has happened.
If you wish to customize the error, you can add onError
callback and throw a custom error based on
your needs.
preventUnauthenticatedAccess
By default, this library will prevent execution flow and throw an error in case of an authentication error.
Setting this to false
will lead to a null
value in case of authentication issue (and onError
will still get called).
domain
Specifies the Auth0 domain, please note that you need to specify that field with a protocol, for
example: my-domain.us.auth0.com
audience
Specifies the Auth0 audience.
extractTokenFn(context: any)
If you wish to customize the token extraction from your HTTP request, override this function. It
gets the context
built so far as an argument, and you can extract your auth token based on your
setup.
headerName
+ tokenType
If extractTokenFn
is not set, the default behavior of this plugin is to look for req
and
request
in the context, then look for headers
and look for authentication
header (you can
customize it with headerName
). Then, it validates that the token is of type Bearer
(you can
customize it with tokenType
option).
extendContextField
The name of the field to inject to your context
. When the user is valid, the decoded and verified
payload of the JWT is injected. In most cases, the field that you need is sub
(which refers to the
internal Auth0 user identifier).
You can read more about the token structure here: https://auth0.com/docs/tokens/json-web-tokens/json-web-token-structure
By default, the auth0
value is used.
Make sure to specify
audience
field in the client, otherwise you'll get an opaque token instead of a JWT token.
No vulnerabilities found.
No security vulnerabilities found.