mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
Remove Adonisjs Ally
Signed-off-by: Arthur DANJOU <arthurdanjou@outlook.fr>
This commit is contained in:
@@ -30,7 +30,6 @@
|
||||
"@adonisjs/mail",
|
||||
"@adonisjs/view",
|
||||
"@adonisjs/bouncer",
|
||||
"@adonisjs/ally"
|
||||
],
|
||||
"aceProviders": [
|
||||
"@adonisjs/repl"
|
||||
|
||||
@@ -32,12 +32,3 @@ SMTP_HOST=
|
||||
SMTP_PORT=
|
||||
SMTP_USERNAME=
|
||||
SMTP_PASSWORD=
|
||||
|
||||
GITHUB_CLIENT_ID=
|
||||
GITHUB_CLIENT_SECRET=
|
||||
GOOGLE_CLIENT_ID=
|
||||
GOOGLE_CLIENT_SECRET=
|
||||
TWITTER_CLIENT_ID=
|
||||
TWITTER_CLIENT_SECRET=
|
||||
DISCORD_CLIENT_ID=
|
||||
DISCORD_CLIENT_SECRET=
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import User from "App/Models/User";
|
||||
import {AllyUserContract} from "@ioc:Adonis/Addons/Ally";
|
||||
|
||||
export default class AuthController {
|
||||
|
||||
@@ -43,130 +42,4 @@ export default class AuthController {
|
||||
})
|
||||
}
|
||||
|
||||
public async twitter ({ ally, auth, response }: HttpContextContract) {
|
||||
const twitter = ally.use('twitter')
|
||||
|
||||
if (twitter.accessDenied()) {
|
||||
return response.status(403).send({
|
||||
message: 'Access Denied!'
|
||||
})
|
||||
}
|
||||
|
||||
if (twitter.stateMisMatch()) {
|
||||
return response.status(405).send({
|
||||
message: 'Request expired. Retry again!'
|
||||
})
|
||||
}
|
||||
|
||||
if (twitter.hasError()) {
|
||||
return response.status(500).send({
|
||||
message: twitter.getError()
|
||||
})
|
||||
}
|
||||
|
||||
const twitterUser = await twitter.user()
|
||||
const user = await this.createUser(twitterUser)
|
||||
await auth.use('web').login(user, true)
|
||||
return response.status(200).send({
|
||||
user: user
|
||||
})
|
||||
}
|
||||
|
||||
public async discord ({ ally, auth, response }: HttpContextContract) {
|
||||
const discord = ally.use('discord')
|
||||
|
||||
if (discord.accessDenied()) {
|
||||
return response.status(403).send({
|
||||
message: 'Access Denied!'
|
||||
})
|
||||
}
|
||||
|
||||
if (discord.stateMisMatch()) {
|
||||
return response.status(405).send({
|
||||
message: 'Request expired. Retry again!'
|
||||
})
|
||||
}
|
||||
|
||||
if (discord.hasError()) {
|
||||
return response.status(500).send({
|
||||
message: discord.getError()
|
||||
})
|
||||
}
|
||||
|
||||
const discordUser = await discord.user()
|
||||
const user = await this.createUser(discordUser)
|
||||
await auth.use('web').login(user, true)
|
||||
return response.status(200).send({
|
||||
user: user
|
||||
})
|
||||
}
|
||||
|
||||
public async github ({ ally, auth, response }: HttpContextContract) {
|
||||
const github = ally.use('github')
|
||||
|
||||
if (github.accessDenied()) {
|
||||
return response.status(403).send({
|
||||
message: 'Access Denied!'
|
||||
})
|
||||
}
|
||||
|
||||
if (github.stateMisMatch()) {
|
||||
return response.status(405).send({
|
||||
message: 'Request expired. Retry again!'
|
||||
})
|
||||
}
|
||||
|
||||
if (github.hasError()) {
|
||||
return response.status(500).send({
|
||||
message: github.getError()
|
||||
})
|
||||
}
|
||||
|
||||
const githubUser = await github.user()
|
||||
const user = await this.createUser(githubUser)
|
||||
await auth.use('web').login(user, true)
|
||||
return response.status(200).send({
|
||||
user: user
|
||||
})
|
||||
}
|
||||
|
||||
public async google ({ ally, auth, response, }: HttpContextContract) {
|
||||
const google = ally.use('google')
|
||||
|
||||
if (google.accessDenied()) {
|
||||
return response.status(403).send({
|
||||
message: 'Access Denied!'
|
||||
})
|
||||
}
|
||||
|
||||
if (google.stateMisMatch()) {
|
||||
return response.status(405).send({
|
||||
message: 'Request expired. Retry again!'
|
||||
})
|
||||
}
|
||||
|
||||
if (google.hasError()) {
|
||||
return response.status(500).send({
|
||||
message: google.getError()
|
||||
})
|
||||
}
|
||||
|
||||
const googleUser = await google.user()
|
||||
const user = await this.createUser(googleUser)
|
||||
await auth.use('web').login(user, true)
|
||||
return response.status(200).send({
|
||||
user: user
|
||||
})
|
||||
}
|
||||
|
||||
public async createUser (allyUser: AllyUserContract<any>): Promise<User> {
|
||||
return await User.firstOrCreate({
|
||||
email: allyUser.email!,
|
||||
}, {
|
||||
email: allyUser.email!,
|
||||
username: allyUser.name,
|
||||
isConfirmed: allyUser.emailVerificationState === 'verified'
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* Config source: https://git.io/JOdi5
|
||||
*
|
||||
* Feel free to let us know via PR, if you find something broken in this config
|
||||
* file.
|
||||
*/
|
||||
|
||||
import Env from '@ioc:Adonis/Core/Env'
|
||||
import {AllyConfig} from '@ioc:Adonis/Addons/Ally'
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Ally Config
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The `AllyConfig` relies on the `SocialProviders` interface which is
|
||||
| defined inside `contracts/ally.ts` file.
|
||||
|
|
||||
*/
|
||||
const allyConfig: AllyConfig = {
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Github driver
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
github: {
|
||||
driver: 'github',
|
||||
clientId: Env.get('GITHUB_CLIENT_ID'),
|
||||
clientSecret: Env.get('GITHUB_CLIENT_SECRET'),
|
||||
callbackUrl: `${Env.get('BASE_URL')}/auth/github/callback`,
|
||||
},
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Google driver
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
google: {
|
||||
driver: 'google',
|
||||
clientId: Env.get('GOOGLE_CLIENT_ID'),
|
||||
clientSecret: Env.get('GOOGLE_CLIENT_SECRET'),
|
||||
callbackUrl: `${Env.get('BASE_URL')}/auth/google/callback`,
|
||||
},
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Twitter driver
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
twitter: {
|
||||
driver: 'twitter',
|
||||
clientId: Env.get('TWITTER_CLIENT_ID'),
|
||||
clientSecret: Env.get('TWITTER_CLIENT_SECRET'),
|
||||
callbackUrl: `${Env.get('BASE_URL')}/auth/twitter/callback`,
|
||||
},
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Discord driver
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
discord: {
|
||||
driver: 'discord',
|
||||
clientId: Env.get('DISCORD_CLIENT_ID'),
|
||||
clientSecret: Env.get('DISCORD_CLIENT_SECRET'),
|
||||
callbackUrl: `${Env.get('BASE_URL')}/auth/discord/callback`,
|
||||
},
|
||||
}
|
||||
|
||||
export default allyConfig
|
||||
@@ -1,27 +0,0 @@
|
||||
/**
|
||||
* Contract source: https://git.io/JOdiQ
|
||||
*
|
||||
* Feel free to let us know via PR, if you find something broken in this contract
|
||||
* file.
|
||||
*/
|
||||
|
||||
declare module '@ioc:Adonis/Addons/Ally' {
|
||||
interface SocialProviders {
|
||||
github: {
|
||||
config: GithubDriverConfig
|
||||
implementation: GithubDriverContract
|
||||
}
|
||||
google: {
|
||||
config: GoogleDriverConfig
|
||||
implementation: GoogleDriverContract
|
||||
}
|
||||
twitter: {
|
||||
config: TwitterDriverConfig
|
||||
implementation: TwitterDriverContract
|
||||
}
|
||||
discord: {
|
||||
config: DiscordDriverConfig
|
||||
implementation: DiscordDriverContract
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
"youch-terminal": "^1.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@adonisjs/ally": "^4.1.0",
|
||||
"@adonisjs/auth": "^8.0.6",
|
||||
"@adonisjs/bouncer": "^2.2.4",
|
||||
"@adonisjs/core": "~5.1.8",
|
||||
|
||||
@@ -6,23 +6,5 @@ Route.group(() => {
|
||||
|
||||
Route.post('/login', 'AuthController.login')
|
||||
Route.post('/logout', 'AuthController.logout')
|
||||
|
||||
Route.get('/twitter/callback', 'AuthController.twitter')
|
||||
Route.get('/github/callback', 'AuthController.github')
|
||||
Route.get('/google/callback', 'AuthController.google')
|
||||
Route.get('/discord/callback', 'AuthController.discord')
|
||||
|
||||
Route.get('/twitter', async ({ally}) => {
|
||||
return ally.use('twitter').redirect()
|
||||
})
|
||||
Route.get('/github', async ({ally}) => {
|
||||
return ally.use('github').redirect()
|
||||
})
|
||||
Route.get('/google', async ({ally}) => {
|
||||
return ally.use('google').redirect()
|
||||
})
|
||||
Route.get('/discord', async ({ally}) => {
|
||||
return ally.use('discord').redirect()
|
||||
})
|
||||
}).prefix('/auth')
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
"@adonisjs/lucid",
|
||||
"@adonisjs/mail",
|
||||
"@adonisjs/view",
|
||||
"@adonisjs/ally",
|
||||
"@adonisjs/bouncer"
|
||||
]
|
||||
}
|
||||
|
||||
17
yarn.lock
17
yarn.lock
@@ -17,14 +17,6 @@
|
||||
slash "^3.0.0"
|
||||
term-size "^2.2.1"
|
||||
|
||||
"@adonisjs/ally@^4.1.0":
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@adonisjs/ally/-/ally-4.1.0.tgz#6811c77c7862f78279d11f6be52792b0837c1829"
|
||||
integrity sha512-IgyUoV9U/a8iTuRBnR0US8/qV5w+d087dqDdDVbgevGVAPyzwci2KeBGBteNzbZDuF1lhfMAz76rL9rSSbWR9A==
|
||||
dependencies:
|
||||
"@poppinss/oauth-client" "^2.0.4"
|
||||
"@poppinss/utils" "^3.1.3"
|
||||
|
||||
"@adonisjs/application@^5.1.3":
|
||||
version "5.1.3"
|
||||
resolved "https://registry.yarnpkg.com/@adonisjs/application/-/application-5.1.3.tgz#f0afb9a1d6f29afc31a6894c669fc2c67870a601"
|
||||
@@ -449,15 +441,6 @@
|
||||
safe-buffer "5.2.1"
|
||||
uid-safe "2.1.5"
|
||||
|
||||
"@poppinss/oauth-client@^2.0.4":
|
||||
version "2.0.4"
|
||||
resolved "https://registry.yarnpkg.com/@poppinss/oauth-client/-/oauth-client-2.0.4.tgz#26795088b472d580127074b8ec28d868d7feb352"
|
||||
integrity sha512-bl8ITdz0FG1ydCAmXVJxrlEtUm42JZK4yj6jA7CVsVhKhzf8OwG3XY8kVETmh/APp8kH8vSM6u5l+lgPKpdlIA==
|
||||
dependencies:
|
||||
"@types/luxon" "^1.26.5"
|
||||
got "^11.8.2"
|
||||
luxon "^1.27.0"
|
||||
|
||||
"@poppinss/prompts@^1.2.2":
|
||||
version "1.2.2"
|
||||
resolved "https://registry.yarnpkg.com/@poppinss/prompts/-/prompts-1.2.2.tgz#e4c0a582f4782d3a804050a00d80ce461de208e3"
|
||||
|
||||
Reference in New Issue
Block a user