@netsells/nuxtjs-client-secret
v1.0.6
Published
Middleware for getting an access token from your API for your frontend without exposing your client ID and secret
Downloads
8
Keywords
Readme
nuxtjs-client-secret
Middleware for getting an access token from your API for your frontend without exposing your client ID and secret
Installation
yarn add @netsells/nuxtjs-client-secret
Usage
In your nuxtjs config:
modules: [
['@netsells/nuxtjs-client-secret', {
token_url: process.env.TOKEN_API_URL,
grant_type: 'client_credentials',
client_id: process.env.API_PERSONAL_ACCESS_CLIENT_ID,
client_secret: process.env.API_PERSONAL_ACCESS_CLIENT_SECRET,
}],
],
You should set your client secrets in your .env
file, not your nuxtjs config file.
This will set a cookie, access_token
, with the access token returned by your API.
You can then add the necessary authorization headers to your front end requests, e.g. for axios:
import axios from 'axios';
import { getAuthHeaders } from '@netsells/nuxtjs-client-secret';
axios.defaults.headers.common = getAuthHeaders();