@inp-net/churros-client
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

churros-client

The official OAuth2 client for Churros.

Setup

Create an app on Churros developers and get your client ID and secret.

Usage

An example with Express:

import { ChurrosClient } from '@inp-net/churros-client';
import express from 'express';

const churros = new ChurrosClient({
  client_id: 'your client id',
  client_secret: 'your client secret',
  // where you want to redirect the user after login
  redirect_uri: 'http://localhost:3000/callback',
});

const yourApp = express();

yourApp.get('/login', (_, res) => {
  res.redirect(churros.authorizationURL);
});

yourApp.get(churros.redirectURL.pathname, async (req, res) => {
  if (req.query['error']) {
    // Handle error
    res.sendStatus(500);
  }
  const token = await churros.getToken(req.query['code'], req.query['state']);

  // Do something with the token, for example get some user info,
  // or use the GraphQL API for everything else (see https://churros.inpt.fr/graphql in your browser)
  const userInfo = await fetch('https://churros.inpt.fr/identity', {
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });

  res.status(200).json(await userInfo.json());
});

console.info('Listening on http://localhost:3000');
yourApp.listen(3000);

Go to /login to start the process.

Readme

Keywords

none

Package Sidebar

Install

npm i @inp-net/churros-client

Weekly Downloads

2

Version

0.1.2

License

MIT

Unpacked Size

8.48 kB

Total Files

6

Last publish

Collaborators

  • legmask
  • gauben
  • ewen-lbh