mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-26 17:40:27 +01:00
Testing Oauth
This commit is contained in:
@@ -101,10 +101,8 @@ export default class AuthController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async github ({ session, ally, auth, response }: HttpContextContract) {
|
public async github ({ ally, auth, response }: HttpContextContract) {
|
||||||
const github = ally.use('github')
|
const github = ally.use('github')
|
||||||
const redirected_url = await session.get('redirect')
|
|
||||||
await session.forget('redirect')
|
|
||||||
|
|
||||||
if (github.accessDenied()) {
|
if (github.accessDenied()) {
|
||||||
return response.status(403).send({
|
return response.status(403).send({
|
||||||
@@ -126,16 +124,11 @@ export default class AuthController {
|
|||||||
|
|
||||||
const githubUser = await github.user()
|
const githubUser = await github.user()
|
||||||
const user = await this.createUser(githubUser)
|
const user = await this.createUser(githubUser)
|
||||||
await auth.use('web').login(user, true)
|
const authUser: User = await auth.use('web').login(user, true)
|
||||||
if (redirected_url) {
|
return response.status(200).send({
|
||||||
return response.redirect(redirected_url)
|
authUser: authUser,
|
||||||
} else {
|
user: user
|
||||||
return response.status(200).send({
|
})
|
||||||
user,
|
|
||||||
redirected_url: redirected_url,
|
|
||||||
redirected: 'No'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async google ({ ally, auth, response, }: HttpContextContract) {
|
public async google ({ ally, auth, response, }: HttpContextContract) {
|
||||||
|
|||||||
@@ -7,22 +7,21 @@ Route.group(() => {
|
|||||||
Route.post('/login', 'AuthController.login')
|
Route.post('/login', 'AuthController.login')
|
||||||
Route.post('/logout', 'AuthController.logout')
|
Route.post('/logout', 'AuthController.logout')
|
||||||
|
|
||||||
Route.get('/twitter/callback', 'AuthController.twitter')
|
Route.post('/twitter/callback', 'AuthController.twitter')
|
||||||
Route.get('/github/callback', 'AuthController.github')
|
Route.post('/github/callback', 'AuthController.github')
|
||||||
Route.get('/google/callback', 'AuthController.google')
|
Route.post('/google/callback', 'AuthController.google')
|
||||||
Route.get('/discord/callback', 'AuthController.discord')
|
Route.post('/discord/callback', 'AuthController.discord')
|
||||||
|
|
||||||
Route.get('/twitter', async ({ ally}) => {
|
Route.get('/twitter', async ({ ally }) => {
|
||||||
return ally.use('twitter').redirect()
|
return ally.use('twitter').redirect()
|
||||||
})
|
})
|
||||||
Route.get('/github', async ({ request, session, ally}) => {
|
Route.get('/github', async ({ ally }) => {
|
||||||
await session.put('redirect', request.input('redirect'))
|
|
||||||
return ally.use('github').redirect()
|
return ally.use('github').redirect()
|
||||||
})
|
})
|
||||||
Route.get('/google', async ({ ally}) => {
|
Route.get('/google', async ({ ally }) => {
|
||||||
return ally.use('google').redirect()
|
return ally.use('google').redirect()
|
||||||
})
|
})
|
||||||
Route.get('/discord', async ({ ally}) => {
|
Route.get('/discord', async ({ ally }) => {
|
||||||
return ally.use('discord').redirect()
|
return ally.use('discord').redirect()
|
||||||
})
|
})
|
||||||
}).prefix('/auth')
|
}).prefix('/auth')
|
||||||
|
|||||||
Reference in New Issue
Block a user