Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express')
- const axios = require('axios')
- const server = require('./config.js')
- const bodyParser = require('body-parser')
- const cors = require('cors')
- const { response } = require('express')
- const app = express()
- app.use(
- cors({
- origin: server.nuxt
- }),
- bodyParser.json()
- )
- app.get('/', function(req, res) {
- res.send('Security!')
- })
- app.post('/login', function(req, res) {
- var body = {
- username: req.body.username,
- password: req.body.password,
- grant_type: 'password',
- client_id: server.client,
- client_secret: server.secret,
- scope: '*'
- }
- axios.post(server.laravel + '/oauth/token', body, {
- headers: {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json'
- }
- })
- .then((response) => {
- res.send(response.data)
- })
- .catch((errors) => {
- res.status(errors.response.status)
- res.send(errors.response.data)
- })
- })
- app.post('/refresh', function(req, res) {
- var body = {
- refresh_token: req.body.refresh_token,
- grant_type: 'refresh_token',
- client_id: server.client,
- client_secret: server.secret,
- scope: '*'
- }
- axios
- .post(server.laravel + '/oauth/token', body, {
- headers: {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json'
- }
- })
- .then((response) => {
- res.send(response.data)
- })
- .catch((errors) => {
- res.status(errors.response.status)
- res.send(errors.response.data)
- })
- })
- app.listen(server.port, 'localhost')
Advertisement
Add Comment
Please, Sign In to add comment