npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@idio/facebook

v1.1.0

Published

The Facebook OAth Login Routes For The Idio Web Server.

Downloads

1

Readme

@idio/facebook

npm version

@idio/facebook is The Facebook OAth Login Routes For The Idio Web Server.

yarn add -E @idio/facebook

Table Of Contents

API

The package is available by importing its default function:

import facebook from '@idio/facebook'

facebook(  router: Router,  config: Config,): void

Sets up the /auth/facebook and /auth/facebook/redirect paths on the router to enable Facebook App Login. The session middleware needs to be installed to remember the state. The state is destroyed after the redirect.

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/facebook | | scope | string | The scope to ask permissions for. | - | | finish | (ctx, token, data) => {} | 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; |

import facebook from '@idio/facebook'
import idioCore from '@idio/core'

const Server = async () => {
  const { url, router, app } = await idioCore({
    session: { use: true, keys: [process.env.SESSION_KEY || 'dev'] },
    logger: { use: true },
  }, { port: 5000 })
  router.get('/', (ctx) => {
    ctx.body = 'hello world'
  })
  facebook(router, {
    client_id: process.env.CLIENT_ID,
    client_secret: process.env.SECRET,
    scope: 'manage_pages',

  })
  app.use(router.routes())
  return { app, url }
}
http://localhost:5000 
  <-- GET /auth/facebook
  --> GET /auth/facebook 302 19ms 385b
{ body: 'Redirecting to <a href="https://www.facebook.com/dialog/oauth?client_id=273790443337044&amp;redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fauth%2Ffacebook%2Fredirect&amp;state=5190&amp;scope=manage_pages">https://www.facebook.com/dialog/oauth?client_id=273790443337044&amp;redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fauth%2Ffacebook%2Fredirect&amp;state=5190&amp;scope=manage_pages</a>.',
  headers: 
   { location: 'https://www.facebook.com/dialog/oauth?client_id=273790443337044&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fauth%2Ffacebook%2Fredirect&state=5190&scope=manage_pages',
     'content-type': 'text/html; charset=utf-8',
     'content-length': '385',
     'set-cookie': 
      [ 'koa:sess=eyJzdGF0ZSI6NTE5MCwiX2V4cGlyZSI6MTU0NDUyNTE1OTMzNCwiX21heEFnZSI6ODY0MDAwMDB9; path=/; httponly',
        'koa:sess.sig=xhelrdB1iw6iAPnzfii_i9BTvF8; path=/; httponly' ],
     date: 'Mon, 10 Dec 2018 10:45:59 GMT',
     connection: 'close' },
  statusCode: 302,
  statusMessage: 'Found' }

 > Redirect to Dialog https://www.facebook.com/dialog/oauth?client_id=273790443337044&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fauth%2Ffacebook%2Fredirect&state=5190&scope=manage_pages

finish

The config allows to set the finish function that can be used to alter the logic of setting the token on the session or performing additional operations such as storing a new user in the database. The default sets the token on the ctx.session and also sets the user data such as name and id in the ctx.session.user property.

    finish = /* async */ (ctx, token, user, /* next */) => {
      ctx.session.token = token
      ctx.session.user = user
      ctx.redirect('/')
      // await storeInDb(token, user)
      // await next()
    },

Copyright

(c) Idio 2018