Last active
August 16, 2019 15:36
-
-
Save maisonm/6344c2cc5a19efe753a67d0c61469b34 to your computer and use it in GitHub Desktop.
Fetch Auth Token Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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