@idio/mailru
v1.0.0
Published
Mail.Ru OAuth Routes.
Downloads
11
Readme
@idio/mailru
@idio/mailru
is Mail.Ru OAuth Routes For Idio Web Server.
yarn add -E @idio/mailru
Table Of Contents
API
The package is available by importing its default function:
import mailru from '@idio/mailru'
mailru(
router: Router,
config: Config,
): void
Sets up the router to accept the auth/mailru
and auth/mailru/redirect
routes. Protects against man-in-the-middle attacks using a unique code for each session. Gets user details upon successful login.
import('koa').Middleware
Middleware
Config
: Options for the program.
| Name | Type | Description | Default |
| ------------------ | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- |
| client_id* | string | The app's client id. | - |
| client_secret* | string | The app's client secret. | - |
| path | string | The server path to start the login flaw and use for redirect (${path}/redirect
). | /auth/mailru
|
| scope | string | The scope to ask permissions for. See https://api.mail.ru/docs/guides/restapi/#permissions. | - |
| finish | (ctx, token, user) => {} | The function to complete the authentication that receives the token and the data about the user, such as name and id. The default function redirects to /
. | setSession; redirect;
|
| error | (ctx, error, error_description, next) => {} | The function to be called in case of error. If not specified, the middleware will throw an internal server error. | throw;
|
| session | Middleware | The configured session middleware in case the session
property is not globally available on the context. | - |
/* yarn example/ */
import dotenv from '@demimonde/dotenv'
import core from '@idio/core'
import mailru from '@idio/mailru'
dotenv()
;(async () => {
const { url, router, app, middleware: {
session,
} } = await core({
session: { use: true, keys: [process.env.SESSION_KEY] },
})
mailru(router, {
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
session,
})
app.use(router.routes())
console.log(`${url}/auth/mailru`)
})()