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.
- Host: GitHub
- URL: https://github.com/idiocc/mailru
- Owner: idiocc
- License: mit
- Created: 2019-01-30T06:36:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-30T09:38:57.000Z (over 7 years ago)
- Last Synced: 2025-06-13T10:07:33.248Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://idio.cc
- Size: 43 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
#
@idio/mailru
[](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 for Idio
2019
Tech Nation Visa Sucks