An open API service indexing awesome lists of open source software.

https://github.com/idiocc/mailru

Mail.Ru OAuth Routes.
https://github.com/idiocc/mailru

Last synced: 12 months ago
JSON representation

Mail.Ru OAuth Routes.

Awesome Lists containing this project

README

          

# @idio/mailru

[![npm version](https://badge.fury.io/js/%40idio%2Fmailru.svg)](https://npmjs.org/package/@idio/mailru)

`@idio/mailru` is Mail.Ru OAuth Routes For Idio Web Server.

```sh
yarn add -E @idio/mailru
```

## Table Of Contents

- [Table Of Contents](#table-of-contents)
- [API](#api)
- [`mailru(router: Router, config: Config)`](#mailrurouter-routerconfig-config-void)
* [`Config`](#type-config)
- [Copyright](#copyright)

## API

The package is available by importing its default function:

```js
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](#type-middleware)_ | The configured session middleware in case the `session` 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`)
})()
```

## Copyright




Art Deco



© Art Deco for Idio
2019


Idio




Tech Nation Visa



Tech Nation Visa Sucks