1.0.0 • Published 5 years ago

@idio/mailru v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@idio/mailru

npm version

@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.

NameTypeDescriptionDefault
client_id*stringThe app's client id.-
client_secret*stringThe app's client secret.-
pathstringThe server path to start the login flaw and use for redirect (${path}/redirect)./auth/mailru
scopestringThe 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;
sessionMiddlewareThe 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`)
})()

Copyright