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

@vtfk/react-oidc

v1.0.0

Published

OIDC (React hook)

Downloads

2

Readme

@vtfk/react-oidc

OIDC (React hook)

Install

npm install --save @vtfk/react-oidc

Usage

config.js

export const config = {
  authority: 'https://oidc-ver2.difi.no/idporten-oidc-provider/.well-known/openid-configuration',
  client_id: 'client-id',
  client_secret: 'client-secret',
  redirect_uri: 'http://localhost:3000',
  silent_redirect_uri: 'http://localhost:3000',
  post_logout_redirect_uri: 'https://www.vtfk.no/',
  response_type: 'code',
  scope: 'openid profile',
  loadUserInfo: true,
  acr_values: 'Level3'
}

index.js

```jsx
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import { IDPortenProvider } from '@vtfk/react-oidc'
import { auth } from './config'

ReactDOM.render(
  <React.StrictMode>
    <IDPortenProvider config={auth}>
      <App />
    </IDPortenProvider>
  </React.StrictMode>,
  document.getElementById('root')
)

App.js

const App = () => {
  const { isAuthenticated, login, logout, authStatus, loginError } = useSession()

  if (['pending'].includes(authStatus)) {
    return <div>Loading...</div>
  }

  if (!isAuthenticated) {
    console.log('app-!isAuth')
    login()
    return <></>
  }

  if (isAuthenticated && authStatus === 'finished') {
    return <div>Hello authenticated user!</div>
  }
}

useSession()

The useSession() hook has these methods and objects available:

  • isAuthenticated (bool)
  • authStatus (string) - values are: pending, finished, rejected, unknown
  • user (object) - user object from ID-porten - example
  • token (string) - access_token from ID-porten
  • idToken (string) - id_token from ID-porten
  • loginError (object) - login error object
  • login (function) - trigger login
  • logout (function) - trigger logout (clears session storage and redirects to azure)

User object

{
  "sub": "autogenerated", // subject identifier - an unique identifier for the authenticated user. The value is pairwise, meaning a given client will always get the same value, whilst different clients do not get equal values for the same user
  "amr": [ // "Authentication Method References” - Method of authentication
      "Minid-PIN"
  ],
  "pid": "ssn", // "Personidentifikator” - the Norwegian national ID number (fødselsnummer/d-nummer) of the autenticated end user. This claim is not included if no_pid scope was requested or pre-registered on the client
  "locale": "nb", // The language selected by the user during the authentication in ID-porten
  "sid": "autogenerated", // session id - an unique identifier for end user session at ID-porten. May be needed when performing logout
  "acr": "Level3", // "Authentication Context Class Reference” - The security level of assurance for the authentication. Possible values are Level3 (i.e. MinID was used) or Level4 (other eIDs). The level must be validated by the client
  "auth_time": 1651221115, // Timestamp indicating when the authentication was performed
  "jti": "autogenerated" // jwt id - unique identifer for a given token
}

License

MIT © Vestfold og Telemark fylkeskommune