@julienbenac/ally-gerermesaffaires
v1.0.2
Published
GererMesAffaires driver for AdonisJS Ally
Downloads
222
Maintainers
Readme
@julienbenac/ally-gerermesaffaires
@julienbenac/ally-gerermesaffaires
is a GererMesAffaires driver for AdonisJS Ally.
Getting Started
First of all, if you haven't already done so, you need to install and configure the @adonisjs/ally
package to implement social authentication in your AdonisJS application.
node ace add @adonisjs/ally
After going through the first step, you can now download the @julienbenac/ally-gerermesaffaires
package.
npm install @julienbenac/ally-gerermesaffaires
Next, configure the package by running the following command. This command will update the .env
and start/env.ts
files with the environment variables.
node ace configure @julienbenac/ally-gerermesaffaires
Then register the service inside the configuration file config/ally.ts
.
// config/ally.ts
import env from '#start/env'
import { defineConfig } from '@adonisjs/ally'
import { gerermesaffaires } from '@julienbenac/ally-gerermesaffaires'
const allyConfig = defineConfig({
gerermesaffaires: gerermesaffaires({
clientId: env.get('GERERMESAFFAIRES_CLIENT_ID'),
clientSecret: env.get('GERERMESAFFAIRES_CLIENT_SECRET') || '',
callbackUrl: env.get('GERERMESAFFAIRES_CALLBACK_URL'),
env: env.get('GERERMESAFFAIRES_ENV'),
}),
})
Finally, you can use the GererMesAffaires driver in your AdonisJS application as below.
// start/routes.ts
import router from '@adonisjs/core/services/router'
router.get('/gerermesaffaires', ({ response }) => {
return response.send('<a href="/gerermesaffaires/redirect"> Login with GererMesAffaires </a>')
})
router.get('/gerermesaffaires/redirect', ({ ally }) => {
return ally.use('gerermesaffaires').redirect((request) => {
request.scopes(['openid', 'collaborator', 'profile', 'address', 'email', 'phone'])
})
})
router.get('/gerermesaffaires/callback', async ({ ally }) => {
const gerermesaffaires = ally.use('gerermesaffaires')
if (gerermesaffaires.accessDenied()) {
return 'Access was denied.'
}
if (gerermesaffaires.hasError()) {
return gerermesaffaires.getError()
}
if (gerermesaffaires.stateMisMatch()) {
return 'State mismatch.'
}
return await gerermesaffaires.user()
})