[refactor] login as separated page
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
const express = require('express')
|
||||
const OAuthServer = require('express-oauth-server')
|
||||
const oauth = express.Router()
|
||||
const bodyParser = require('body-parser')
|
||||
const oauthController = require('./controller/oauth')
|
||||
|
||||
const oauthServer = new OAuthServer({
|
||||
@@ -12,61 +11,30 @@ const oauthServer = new OAuthServer({
|
||||
})
|
||||
|
||||
oauth.oauth = oauthServer
|
||||
oauth.use(bodyParser.json())
|
||||
oauth.use(bodyParser.urlencoded({ extended: false }))
|
||||
oauth.use(express.urlencoded({ extended: false }))
|
||||
oauth.use(express.json())
|
||||
|
||||
// post token
|
||||
// oauth.post(oauthServer.authorize())
|
||||
oauth.post('/token', (req, res, next) => {
|
||||
return oauthServer.token()(req, res, next)
|
||||
.then(code => {
|
||||
console.error('dopo il token', code)
|
||||
})
|
||||
.catch(e => console.error('nel catch ', e))
|
||||
})
|
||||
oauth.post('/token', oauthServer.token())
|
||||
|
||||
|
||||
/**
|
||||
* create a new application
|
||||
*/
|
||||
oauth.get('/authorize', async (req, res, next) => {
|
||||
if (!req.user) {
|
||||
return res.redirect(`/?ref=login&redirect=${req.path}&client_id=${req.query.client_id}&redirect_uri=${req.query.redirect_uri}`)
|
||||
return res.redirect(`/login?redirect=${req.path}&client_id=${req.query.client_id}&redirect_uri=${req.query.redirect_uri}`)
|
||||
}
|
||||
|
||||
return oauthServer.authorize()(req, res, next).then(code => {
|
||||
console.error('dentro authorize?', code)
|
||||
console.error(req.locals)
|
||||
return
|
||||
// return res.redirect(`/?ref=authorize&client_id=${req.query.client_id}&redirect_uri=${req.query.redirect_uri}&code=${code}`)
|
||||
}).catch(e => { console.error('porcodio catch ', e) })
|
||||
return oauthServer.authorize()
|
||||
})
|
||||
|
||||
oauth.post('/authorize', (req, res, next) => {
|
||||
if (!req.user) {
|
||||
return res.redirect(`/?ref=login&redirect=${req.path}&client_id=${req.query.client_id}&redirect_uri=${req.query.redirect_uri}`)
|
||||
return res.redirect(`/login?redirect=${req.path}&client_id=${req.query.client_id}&redirect_uri=${req.query.redirect_uri}`)
|
||||
}
|
||||
console.error('sono nel post di authorize!')
|
||||
const ret = oauthServer.authorize()
|
||||
console.error('PORCODIO ', ret)
|
||||
return ret(req, res, next).then(code => {
|
||||
console.error('DAJE CHE ARRIVO QUI ', code)
|
||||
console.error(req.locals)
|
||||
next()
|
||||
}).catch(e => console.error('CATCH ', e))
|
||||
|
||||
return oauthServer.authorize()
|
||||
})
|
||||
|
||||
oauth.get('/login', (req, res) => {
|
||||
res.render('login', {
|
||||
client_id: req.query.client_id,
|
||||
redirect_uri: req.query.redirect_uri,
|
||||
redirect: req.query.redirect,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
oauth.use((err, req, res, next) => {
|
||||
res.status(400).json(err)
|
||||
res.status(500).json(err)
|
||||
})
|
||||
|
||||
// oauth.post('/login', )
|
||||
|
||||
Reference in New Issue
Block a user