Skip to content

Instantly share code, notes, and snippets.

@maisonm
Last active August 16, 2019 15:36
Show Gist options
  • Save maisonm/6344c2cc5a19efe753a67d0c61469b34 to your computer and use it in GitHub Desktop.
Save maisonm/6344c2cc5a19efe753a67d0c61469b34 to your computer and use it in GitHub Desktop.
Fetch Auth Token Controller
exports.authenticate_user = (req, res, next) => {
const { username, password } = req.body;
const API_URL = require('../../utils/constants/api_urls/api_urls');
const { fetchToken } = API_URL;
//DEVELOPMENT VALUES FOR TESTING ONLY
const body = {
client_id: 'cp',
client_secret: 'secret',
grant_type: 'password',
scope: 'openid offline_access cpapi_read',
username,
password
};
//Fetch configuration
const fetchConfig = {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: JSON.stringify(body)
};
//Log response to terminal for now
fetch(fetchToken, fetchConfig)
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment