All Projects → Camji55 → nexus-plugin-jwt-auth

Camji55 / nexus-plugin-jwt-auth

Licence: MIT license
Basic jsonwebtoken authentication plugin for The Nexus Framework

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to nexus-plugin-jwt-auth

springboot-graphql-sqqr-jwt-demo
GraphQL java backend representing the right way to authenticate/authorize using Spring boot, graphql-spqr & jsonwebtoken
Stars: ✭ 28 (-49.09%)
Mutual labels:  jwt-token, jsonwebtoken
TokenBreaker
JSON RSA to HMAC and None Algorithm Vulnerability POC
Stars: ✭ 51 (-7.27%)
Mutual labels:  jwt-token, jsonwebtoken
Jwt Cli
A super fast CLI tool to decode and encode JWTs built in Rust
Stars: ✭ 336 (+510.91%)
Mutual labels:  jwt-token, jsonwebtoken
Jose2go
Golang (GO) implementation of Javascript Object Signing and Encryption specification
Stars: ✭ 150 (+172.73%)
Mutual labels:  jwt-token
Vue.netcore
.NetCore+Vue2/Vue3+Element plus,前后端分离,不一样的快速开发框架;提供Vue2、Vue3版本,。http://www.volcore.xyz/
Stars: ✭ 2,338 (+4150.91%)
Mutual labels:  jwt-token
Frank jwt
JSON Web Token implementation in Rust.
Stars: ✭ 227 (+312.73%)
Mutual labels:  jwt-token
WarmSearch
🏫 失物招领网站 (SpringBoot + MybatisPlus + JWT) 实现前后端分离项目的后台管理系统
Stars: ✭ 38 (-30.91%)
Mutual labels:  jwt-token
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (+165.45%)
Mutual labels:  jwt-token
MyAPI
A template to create awesome APIs easily ⚡️
Stars: ✭ 117 (+112.73%)
Mutual labels:  jwt-token
Reallysimplejwt
A really simple library to generate JSON Web Tokens in PHP.
Stars: ✭ 218 (+296.36%)
Mutual labels:  jwt-token
Apple Music Token Generator
Stars: ✭ 208 (+278.18%)
Mutual labels:  jwt-token
Doorkeeper Jwt
JWT Token support for Doorkeeper
Stars: ✭ 174 (+216.36%)
Mutual labels:  jwt-token
Firebase Esp8266
ESP8266 Firebase RTDB Arduino Library
Stars: ✭ 228 (+314.55%)
Mutual labels:  jwt-token
Hltool
Go 开发常用工具库, Google2步验证客户端,AES加密解密,RSA加密解密,钉钉机器人,邮件发送,JWT生成解析,Log,BoltDB操作,图片操作,json操作,struct序列化
Stars: ✭ 151 (+174.55%)
Mutual labels:  jwt-token
MyJWT
A cli for cracking, testing vulnerabilities on Json Web Token(JWT)
Stars: ✭ 92 (+67.27%)
Mutual labels:  jsonwebtoken
Meetingfilm
基于微服务架构的在线电影购票平台
Stars: ✭ 149 (+170.91%)
Mutual labels:  jwt-token
Spring Boot Start Current
Spring Boot 脚手架 Mybatis Spring Security JWT 权限 Spring Cache + Redis
Stars: ✭ 246 (+347.27%)
Mutual labels:  jwt-token
Jwt Spring Security Jpa
Backend MVP showcasing JWT (Json Web Token) authentication with multiple login, timeout / refresh / logout (with in memory invalidation) using Spring Security & MySQL JPA.
Stars: ✭ 202 (+267.27%)
Mutual labels:  jwt-token
Firebase Esp32
ESP32 Firebase RTDB Arduino Library
Stars: ✭ 204 (+270.91%)
Mutual labels:  jwt-token
Apns2
⚡ HTTP/2 Apple Push Notification Service (APNs) push provider for Go — Send push notifications to iOS, tvOS, Safari and OSX apps, using the APNs HTTP/2 protocol.
Stars: ✭ 2,569 (+4570.91%)
Mutual labels:  jwt-token

header

Contents

Installation

npm install nexus-plugin-jwt-auth

Example Usage

Find full examples using both the built in permissions system or by leveragering nexus-plugin-shield:

Setup

// app.ts

import { use } from 'nexus'
import { auth } from 'nexus-plugin-jwt-auth'

// Enables the JWT Auth plugin without permissions
use(auth({
  appSecret: "<YOUR SECRET>" // optional if using custom verify function
}))

You may now access the token object and it's properties on the Nexus context.

Permissions

Basic permissions can be added too.

// app.ts

import { use } from 'nexus'
import { auth } from 'nexus-plugin-jwt-auth'

// Define the paths you'd like to protect
const protectedPaths = [
    'Query.me',
    'Query.filterPosts',
    'Query.post',
    'Mutation.createDraft',
    'Mutation.deletePost',
    'Mutation.publish'
]

// Enables the JWT Auth plugin with permissions
use(auth({
  appSecret: "<YOUR SECRET>", // optional if using custom verify function
  protectedPaths // optional
}))

Stored Properties

You can also access properties stored in the token.

In this example I sign the token on signup or login then store the userId in the token to be accessed directly in a query or mutation to find the authed user.

// Query.ts

import { schema } from 'nexus'

schema.queryType({
  definition(t) {
    t.field('me', {
      type: 'User',
      async resolve(_root, _args, ctx) {
        const user = await ctx.db.user.findOne({
          where: {
            id: ctx.token.userId // This is the token object passed through the context
          }
        })

        if (!user) {
          throw new Error('No such user exists')
        }

        return user
      }
    })
  }
})

Use cookie instead of Authorization header

import { use, server } from "nexus"
import cookieParser from "cookie-parser" // Set esModuleInterop: true in tsconfig.json

// Add the cookie-parser middleware to Express
server.express.use(cookieParser())

// Enables the JWT Auth plugin with cookies
use(auth({
  // ...
  useCookie: true,
  cookieName: "token"
}))

Don't forget to set credentials: true in your GraphQL client or the cookie will not be sent to the server.

Contributing

Please read CONTRIBUTING.md

License

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].