Mail.Ru OAuth Routes.
npm install @idio/mailru
@idio/mailru is Mail.Ru OAuth Routes For Idio Web Server.
``sh`
yarn add -E @idio/mailru
- Table Of Contents
- API
- mailru(router: Router, config: Config)
* Config
- Copyright
The package is available by importing its default function:
`js`
import mailru from '@idio/mailru'
router: Router,
config: Config,
): voidSets 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; |throw;
| 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. | |session
| session | _Middleware_ | The configured session middleware in case the property is not globally available on the context. | - |
`js
/ 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)``
})()
![]() | © Art Deco for Idio 2019 | ![]() | Tech Nation Visa Sucks |
|---|