rvkolosov

Untitled

Mar 2nd, 2021
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express')
  2. const axios = require('axios')
  3. const server = require('./config.js')
  4. const bodyParser = require('body-parser')
  5. const cors = require('cors')
  6. const { response } = require('express')
  7. const app = express()
  8. app.use(
  9.   cors({
  10.     origin: server.nuxt
  11.   }),
  12.   bodyParser.json()
  13. )
  14. app.get('/', function(req, res) {
  15.   res.send('Security!')
  16. })
  17. app.post('/login',  function(req, res) {
  18.   var body = {
  19.     username: req.body.username,
  20.     password: req.body.password,
  21.     grant_type: 'password',
  22.     client_id: server.client,
  23.     client_secret: server.secret,
  24.     scope: '*'
  25.   }
  26.  
  27.   axios.post(server.laravel + '/oauth/token', body, {
  28.       headers: {
  29.         'Content-Type': 'application/json',
  30.         'Accept': 'application/json'
  31.       }
  32.     })
  33.     .then((response) => {
  34.       res.send(response.data)
  35.     })
  36.     .catch((errors) => {
  37.       res.status(errors.response.status)
  38.       res.send(errors.response.data)
  39.     })
  40.  
  41. })
  42. app.post('/refresh', function(req, res) {
  43.   var body = {
  44.     refresh_token: req.body.refresh_token,
  45.     grant_type: 'refresh_token',
  46.     client_id: server.client,
  47.     client_secret: server.secret,
  48.     scope: '*'
  49.   }
  50.   axios
  51.     .post(server.laravel + '/oauth/token', body, {
  52.       headers: {
  53.         'Content-Type': 'application/json',
  54.         'Accept': 'application/json'
  55.       }
  56.     })
  57.     .then((response) => {
  58.       res.send(response.data)
  59.     })
  60.     .catch((errors) => {
  61.       res.status(errors.response.status)
  62.       res.send(errors.response.data)
  63.     })
  64. })
  65. app.listen(server.port, 'localhost')
  66.  
Advertisement
Add Comment
Please, Sign In to add comment