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

metero-auth-react

v1.2.0

Published

Metero auth api for React JS.

Downloads

8

Readme

metero-auth-react

Metero auth api for React JS.

NPM JavaScript Style Guide

Install

npm install --save metero-auth-react

Documentation

MeteroAuth

const onSuccess = authData => {
  // e.g. Save authData
}

const onFail = error => {
  // e.g. Show error for user
}

return (
  <MeteroAuth
    clientId="test"
    clientSecret="123"
    redirectURI="http://localhost:3000/"
    scope="USER_WRITE POST_CREATE POST_WRITE POST_DELETE"
    onSuccess={onSuccess}
    onFail={onFail}
    width="500"
    height="500"
  >
    <button>Login</button>
  </MeteroAuth>
)

This code will display a normal button with text 'login'. But when user will click this button, it will create popup window. In this popup window will be metero login page. After user will login it will redirect to consent page. In consent user may accept or cancel authorization. When user will accept the authorization. It will redirect to redirectURI with code. Then with this code it will make a post request to token endpoint to fetch access token. Basically it's realization of OAuth2 Authorization code grant with PKCE challenge flow.


clientId - string - Your client id.

clientSecret - string - Your client secret.

redirectURI - string - Url where server will redirect after user accepted authorization.

scope - string - List of scopes separated by space your app wants to access.

onSuccess - function - It will execute when access token will receive. authData contains accessToken, refreshToken, use it whit refreshAuth function to generate new access token, accessTokenExpiresAt - date until which access token is valid and idToken, contains information about logged user (from ODIC).

onFail - function - It will execute when something went wrong. error is AxiosError or CSRFError (both aren't exported).

width - number - Optional parameter. Represents width of popup window.

height - number - Optional parameter. Represents height of popup window.

refreshAuth

refreshAuth({
  refreshToken: refreshToken,
  clientId: clientId,
  clientSecret: clientSecret,
  scope: scope
})
  .then(authData => {
    // e.g. Save authData
  })
  .catch(error => {
    // e.g. Show error for user
  })

It will make a post request to fetch new access token. Basically it's of OAuth2 Refresh token grant flow.


refreshToken - string - Refresh token from authData.

clientId - string - Your client id.

clientSecret - string - Your client secret.

scope - string - List of scopes separated by space your app wants to access.

As you might have guessed it will return Promise. In case of success you will get authData. In case of failure you will get AxiosError.

decodeIdToken

const userInfo = decodeIdToken(idToken);
// userInfo = {
//   iri: '//api.metero.pp.ua/users/11',
//   id: 11,
//   username: 'example_user',
//   name: 'Example User',
//   email: '[email protected]'
// }

Use to get information about logger user from id token.


idToken - string - Id token tou want decode.

Basically id token is just jwt token. This function will return it payload, but it won't include iss, aud, iat and exp fields. And 'sub' field will be renamed to 'iri'.

AxiosError

Basically it is normal javascript Error. But it extended with originalError filed. That contains error from axios.

CSRFError

Basically it is normal javascript Error. But it extended with expectedToken and actualToken. expectedToken contains csrf token you should get and actualToken contains csrf token you got.

License

MIT © ArtemGolovko