Giter VIP home page Giter VIP logo

native-auth's Introduction

Native Authenticator for JavaScript

Native Authenticator for JavaScript and TypeScript (written in TypeScript).

Distribution

npm

Example

Client-side

const client = new NativeAuthClient();
const init = await client.initialize();

// obtain signature by signing token

const accessToken = client.getToken(address, init, signature);

Client-side config

When initializing the client object, an optional config can also be specified with the following properties:

{
  // When used from within a browser, will contain the hostname by default.
  // It can be overridden for special situations
  // Note: The server-side component will validate the `origin` header, which must
  // match with the provided host in the client-side configuration
  host: string = 'myApp.com';

  // The endpoint from where the current block information will be fetched upon initialization.
  // The default value points to the mainnet API, but can be overridden to be network-specific
  // or to point to a self-hosted location
  apiUrl: string = 'https://api.elrond.com';

  // TTL that will be encoded in the access token.
  // This value will also be validated by the server and must not be greater than the maximum ttl allowed.
  // Default: one day (86400 seconds)
  expirySeconds: number = 60 * 60 * 24;
}

Server-side

const server = new NativeAuthServer();
const result = await server.validate(accessToken);

Server-side config

{
  // The endpoint from where the current block information will be fetched upon validation.
  // The default value points to the mainnet API, but can be overridden to be network-specific
  // or to point to a self-hosted location
  apiUrl: string = 'https://api.elrond.com';

  // An optional list of accepted hosts in case the server component must validate the incoming requests
  // by domain
  acceptedHosts: string[] = [];

  // Maximum allowed TTL from the token.
  // Default: one day (86400 seconds)
  maxExpirySeconds: number = 86400;

  // An optional implementation of the caching interface used for resolving 
  // latest block timestamp and also to validate and provide a block timestamp given a certain block hash.
  // It can be integrated with popular caching mechanisms such as redis
  cache?: NativeAuthCacheInterface;
}

native-auth's People

Contributors

tanghel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.