mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
Working on OAuth
This commit is contained in:
@@ -27,7 +27,7 @@ const allyConfig: AllyConfig = {
|
||||
driver: 'github',
|
||||
clientId: Env.get('GITHUB_CLIENT_ID'),
|
||||
clientSecret: Env.get('GITHUB_CLIENT_SECRET'),
|
||||
callbackUrl: `${Env.get('HOST')}:${Env.get('PORT')}/auth/github`,
|
||||
callbackUrl: `${Env.get('BASE_URL')}:${Env.get('PORT')}/auth/github/callback`,
|
||||
},
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -38,7 +38,7 @@ const allyConfig: AllyConfig = {
|
||||
driver: 'twitter',
|
||||
clientId: Env.get('TWITTER_CLIENT_ID'),
|
||||
clientSecret: Env.get('TWITTER_CLIENT_SECRET'),
|
||||
callbackUrl: `${Env.get('HOST')}:${Env.get('PORT')}/auth/twitter`,
|
||||
callbackUrl: `${Env.get('BASE_URL')}:${Env.get('PORT')}/auth/twitter/callback`,
|
||||
},
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -49,7 +49,7 @@ const allyConfig: AllyConfig = {
|
||||
driver: 'google',
|
||||
clientId: Env.get('GOOGLE_CLIENT_ID'),
|
||||
clientSecret: Env.get('GOOGLE_CLIENT_SECRET'),
|
||||
callbackUrl: `${Env.get('HOST')}:${Env.get('PORT')}/auth/google`,
|
||||
callbackUrl: `${Env.get('BASE_URL')}:${Env.get('PORT')}/auth/google/callback`,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -17,69 +17,8 @@ import { AuthConfig } from '@ioc:Adonis/Addons/Auth'
|
||||
|
|
||||
*/
|
||||
const authConfig: AuthConfig = {
|
||||
guard: 'web',
|
||||
guard: 'api',
|
||||
guards: {
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Web Guard
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Web guard uses classic old school sessions for authenticating users.
|
||||
| If you are building a standard web application, it is recommended to
|
||||
| use web guard with session driver
|
||||
|
|
||||
*/
|
||||
web: {
|
||||
driver: 'session',
|
||||
|
||||
provider: {
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Name of the driver
|
||||
|
|
||||
*/
|
||||
driver: 'lucid',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Identifier key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The identifier key is the unique key on the model. In most cases specifying
|
||||
| the primary key is the right choice.
|
||||
|
|
||||
*/
|
||||
identifierKey: 'id',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Uids
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Uids are used to search a user against one of the mentioned columns. During
|
||||
| login, the auth module will search the user mentioned value against one
|
||||
| of the mentioned columns to find their user record.
|
||||
|
|
||||
*/
|
||||
uids: ['email'],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Model
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The model to use for fetching or finding users. The model is imported
|
||||
| lazily since the config files are read way earlier in the lifecycle
|
||||
| of booting the app and the models may not be in a usable state at
|
||||
| that time.
|
||||
|
|
||||
*/
|
||||
model: () => import('App/Models/User'),
|
||||
},
|
||||
},
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| OAT Guard
|
||||
|
||||
@@ -55,19 +55,6 @@ declare module '@ioc:Adonis/Addons/Auth' {
|
||||
|
|
||||
*/
|
||||
interface GuardsList {
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Web Guard
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The web guard uses sessions for maintaining user login state. It uses
|
||||
| the `user` provider for fetching user details.
|
||||
|
|
||||
*/
|
||||
web: {
|
||||
implementation: SessionGuardContract<'user', 'web'>,
|
||||
config: SessionGuardConfig<'user'>,
|
||||
},
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| OAT Guard
|
||||
|
||||
@@ -10,10 +10,6 @@ export default class ApiTokens extends BaseSchema {
|
||||
table.string('name').notNullable()
|
||||
table.string('type').notNullable()
|
||||
table.string('token', 64).notNullable()
|
||||
|
||||
/**
|
||||
* "useTz: true" utilizes timezone option in PostgreSQL and MSSQL
|
||||
*/
|
||||
table.timestamp('expires_at', { useTz: true }).nullable()
|
||||
table.timestamp('created_at', { useTz: true }).notNullable()
|
||||
})
|
||||
6
env.ts
6
env.ts
@@ -17,7 +17,7 @@ import Env from '@ioc:Adonis/Core/Env'
|
||||
export default Env.rules({
|
||||
|
||||
//App
|
||||
HOST: Env.schema.string({ format: 'host' }),
|
||||
HOST: Env.schema.string(),
|
||||
PORT: Env.schema.number(),
|
||||
APP_KEY: Env.schema.string(),
|
||||
APP_NAME: Env.schema.string(),
|
||||
@@ -32,7 +32,7 @@ export default Env.rules({
|
||||
|
||||
//Mysql
|
||||
DB_CONNECTION: Env.schema.string(),
|
||||
MYSQL_HOST: Env.schema.string({ format: 'host' }),
|
||||
MYSQL_HOST: Env.schema.string(),
|
||||
MYSQL_PORT: Env.schema.number(),
|
||||
MYSQL_USER: Env.schema.string(),
|
||||
MYSQL_PASSWORD: Env.schema.string.optional(),
|
||||
@@ -47,7 +47,7 @@ export default Env.rules({
|
||||
//Utils
|
||||
GITHUB_TOKEN: Env.schema.string(),
|
||||
GITHUB_SOURCE: Env.schema.string({ format: 'url' }),
|
||||
BASE_URL: Env.schema.string({ format: 'url' }),
|
||||
BASE_URL: Env.schema.string(),
|
||||
API_VERSION: Env.schema.string(),
|
||||
|
||||
//Mails
|
||||
|
||||
@@ -26,7 +26,7 @@ Route.get('/source', async ({response}: HttpContextContract) => {
|
||||
return response.redirect(Env.get('GITHUB_SOURCE'))
|
||||
})
|
||||
|
||||
Route.get('health', async ({response}: HttpContextContract) => {
|
||||
Route.get('/health', async ({response}: HttpContextContract) => {
|
||||
const report = await HealthCheck.getReport()
|
||||
const isLive = await HealthCheck.isLive()
|
||||
const isReady = await HealthCheck.isReady()
|
||||
@@ -36,31 +36,20 @@ Route.get('health', async ({response}: HttpContextContract) => {
|
||||
// ArtAPI
|
||||
Route.get('/profile', 'ProfileController.me')
|
||||
Route.get('/locations', 'LocationsController.get')
|
||||
//Route.get('/stats', 'StatsController.get')
|
||||
Route.get('/stats', 'StatsController.get')
|
||||
Route.get('/states', 'StatesController.get')
|
||||
Route.get('/projects', 'ProjectsController.get')
|
||||
|
||||
Route.resource('users', 'UsersController').only(['index', 'show'])
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/', 'FileController.index')
|
||||
Route.get('/:filename', async ({ response, params }) => {
|
||||
response.download(Application.makePath('storage', params.filename))
|
||||
})
|
||||
}).prefix('/files')
|
||||
|
||||
Route.group(() => {
|
||||
Route.resource('users', 'UsersController').only(['store', 'update', 'destroy'])
|
||||
Route.resource('files', 'FileController').only(['store', 'destroy'])
|
||||
Route.post('/locations', 'LocationsController.store')
|
||||
Route.post('/projects', 'ProjectsController.store')
|
||||
}).middleware('auth:web')
|
||||
|
||||
Route.group(() => {
|
||||
Route.post('form', 'FormsController.send')
|
||||
|
||||
Route.post('states/:state', 'StatesController.set')
|
||||
|
||||
Route.resource('users', 'UsersController')
|
||||
Route.resource('files', 'FileController').only(['store', 'destroy'])
|
||||
|
||||
Route.post('/locations', 'LocationsController.store')
|
||||
Route.post('/projects', 'ProjectsController.store')
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/:slug', 'PostsController.getLikes')
|
||||
Route.post('/:slug/like', 'PostsController.like')
|
||||
@@ -72,7 +61,15 @@ Route.group(() => {
|
||||
|
||||
Route.get('guestbook', 'GuestBookController.get')
|
||||
Route.post('guestbook', 'GuestBookController.store')
|
||||
}).middleware('auth:api')
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/', 'FileController.index')
|
||||
Route.get('/:filename', async ({ response, params }) => {
|
||||
response.download(Application.makePath('storage', params.filename))
|
||||
})
|
||||
}).prefix('/files')
|
||||
|
||||
}).middleware('auth')
|
||||
|
||||
Route.group(() => {
|
||||
Route.get('/me', 'AuthController.user').middleware('auth')
|
||||
@@ -88,13 +85,13 @@ Route.group(() => {
|
||||
Route.get('/github/callback', 'AuthController.github')
|
||||
Route.get('/google/callback', 'AuthController.google')
|
||||
|
||||
Route.get('/twitter/redirect', async ({ ally}) => {
|
||||
Route.get('/twitter', async ({ ally }) => {
|
||||
return ally.use('twitter').redirect()
|
||||
})
|
||||
Route.get('/github/redirect', async ({ ally}) => {
|
||||
Route.get('/github', async ({ ally }) => {
|
||||
return ally.use('github').redirect()
|
||||
})
|
||||
Route.get('/google/redirect', async ({ ally}) => {
|
||||
Route.get('/google', async ({ ally }) => {
|
||||
return ally.use('google').redirect()
|
||||
})
|
||||
}).prefix('auth')
|
||||
|
||||
Reference in New Issue
Block a user