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

@gimly-blockchain/rn-did-auth-siop-authenticator

v0.1.2

Published

#### If React Native tools are not installed

Downloads

1

Readme

This library module contains an OP (OpenID Provider) Authenticator implementation that can be used in React Native projects, it's basically a React Native wrapper around the "Self Issued OpenID Provider v2 (SIOP)" library reducing the implementation effort and troubleshooting involved with getting the SIOP library to work in a React Native environment.

Demo project rn-did-siop-example-app implements this library.

To build

If React Native tools are not installed

yarn global add react-native-cli
yarn global add rn-nodeify

Build

  • yarn install
  • yarn build

Usage

To use this helper library you need to implement the following: First you create a new instance of OPAuthenticator. There are two static methods with different parameters:

this.opAuthenticator = OPAuthenticator.newInstance(options)

Use this method for simplified instantiation with only the most common parameters.

opDID: string
opKID: string
opPrivateKey: string
expiresIn: number // (optional, default is 6000ms) 
didMethod: string  // optional, IE. "ethr", "eosio". By default it is taken from the authentication requests did_methods_supported

When using typescript these fields are contained in class OPAuthenticatorOptions.

or for more fine-grained control use the OP.builder() from the SIOP library:

    this.opAuthenticator = OPAuthenticator.newInstanceFromOP(OP.builder()
        .withExpiresIn(expiresIn)
        .addDidMethod("ethr")
        .internalSignature(opPrivateKey, opDID, opKID)
        .registrationBy(PassBy.VALUE)
        .response(ResponseMode.POST)
        .build())

see this openid-provider-siop section for details.

The next step is to get an authentication request from the RP (Relying Party) endpoint. Method "getAuthenticationRequestFromRP" will the call the RP endpoint to retrieve the full authentication request based on a state identifier which has to be part of the QR code data, besides the state field state we also need a redirectUrl field to know at which endpoint we can get the authentication request. When using typescript it takes interface QRCodeValues as parameter.
(In case the entire authentication request is encoded in the QR code this step is not necessary.)

this.authRequestURI = await this.opAuthenticator.getAuthenticationRequestFromRP(qrContent as QRCodeValues)

getAuthenticationRequestFromRP will return (when using typescript) and object for interface ParsedAuthenticationRequestURI. This is the input parameter for then next step:

this.verifiedAuthenticationRequest = await this.opAuthenticator.verifyAuthenticationRequestURI(this.authRequestURI)

When verifyAuthenticationRequestURI method, the verification of authenticity of the request send by the RP succeeds, it will return an object for interface VerifiedAuthenticationRequestWithJWT.

Next there a helper method the extract DID information from the request, but this can also be done from within the VerifiedAuthenticationRequestWithJWT interface.

const rpDid = this.opAuthenticator.rpDidFromAuthenticationRequest(this.verifiedAuthenticationRequest)

rpDidFromAuthenticationRequest will return class RPDID containing DID information

export declare class RPDID {
  id: string;
  alsoKnownAs?: string[];
}

At this point the idea is that you present the DID information and ask the user for permission to send your DID back to the RP by using either a button or biometrics dialog. When the user approves you can call the final method "sendAuthResponse" which will send the requested (and signed) OP did information back to the RP callback endpoint:

 try {
  await this.opAuthenticator.sendAuthResponse(this.verifiedAuthenticationRequest as VerifiedAuthenticationRequestWithJWT)
  this.setState({message: "Login successful"})
} catch (e) {
  this.setState({message: "Error: " + e.message})
} finally {
  ...
}

(Except for rpDidFromAuthenticationRequest all methods will return a promise. Errors are raised using Promise.reject())