Complete, compliant and well tested module for implementing an OAuth2 Server/Provider with fastify in node.js.
This is the fastify wrapper for oauth2-server.
Installation
$ npm install fastify-oauth-server
Quick Start
The module provides one decorator - oauth
.
Use the decorator to get the authentication state.
// ./model.js const argon2 = ; const connect = ; moduleexportsgetAccessToken = async { const db = await ; const token = await dboauth_tokens; let result; if token result = accessToken: tokenaccessToken accessTokenExpiresAt: tokenaccessTokenExpiresAt client: id: tokenclientId expires: tokenaccessTokenExpiresAt user: id: tokenuserId ; return result;}; moduleexportsgetUserFromClient = async { const db = await ; const oauthClient = await dboauth_clients; let result; if oauthClient result = await dbusers; return result;}; moduleexportsgetClient = async { const db = await ; const query = clientId ; if clientSecret queryclientSecret = clientSecret; const client = await dboauth_clients; let result; if client result = clientSecret: clientclientSecret grants: clientgrants id: clientclientId userId: clientuserId ; return result;}; moduleexportsgetRefreshToken = async { const db = await ; const token = await dboauth_tokens; return refreshToken: tokenrefreshToken client: id: tokenclientId user: id: tokenuserId ;}; moduleexportsgetUser = async { const db = await ; let result; const user = await dbusers; let isValid = false; if user isValid = await argon2; if isValid result = Object; return result;}; moduleexportssaveToken = async { const db = await ; const inserted = await dboauth_tokens; let result; if inserted result = accessToken: tokenaccessToken accessTokenExpiresAt: tokenaccessTokenExpiresAt client: id: clientid refreshToken: tokenrefreshToken refreshTokenExpiresAt: tokenrefreshTokenExpiresAt user: id: userid ; return result;}; moduleexportsrevokeToken = async { const db = await ; const result = await dboauth_tokens; return result;}; moduleexports false;
var fastify = ;var oauthserver = ; var app = ; app; app; app; app;