How to use @arcblock/did-auth - 2 common examples

To help you get started, we’ve selected a few @arcblock/did-auth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ArcBlock / forge-js / examples / nextjs-keystone-starter / server / controllers / auth.js View on Github external
const keystone = require('keystone');
const multibase = require('multibase');
const { fromTokenToUnit, bytesToHex } = require('@arcblock/forge-util');
const { fromAddress } = require('@arcblock/forge-wallet');
const { Handlers } = require('@arcblock/did-auth');
const auth = require('../../config/auth');
const KeystoneStorage = require('../../config/storage/keystone');

const handler = new Handlers({
  tokenGenerator: req => req.sessionID + Date.now(),
  tokenStorage: new KeystoneStorage(),
  authenticator: auth,
});

module.exports = app => {
  app.get('/api/session', async (req, res) => {
    res.json(req.session);
  });

  app.post('/api/logout', async (req, res) => {
    req.session.user = null;
    res.json(req.session);
  });

  // Enable payment
github ArcBlock / forge-js / examples / nextjs-keystone-starter / config / auth.js View on Github external
const Mcrypto = require('@arcblock/mcrypto');
const { fromSecretKey, WalletType } = require('@arcblock/forge-wallet');
const { Authenticator } = require('@arcblock/did-auth');

const type = WalletType({
  role: Mcrypto.types.RoleType.ROLE_APPLICATION,
  pk: Mcrypto.types.KeyType.ED25519,
  hash: Mcrypto.types.HashType.SHA3,
});

const wallet = fromSecretKey(process.env.APP_SK, type).toJSON();

module.exports = new Authenticator({
  wallet,
  baseUrl: 'http://wangshijun.natapp1.cc',
  appInfo: {
    chainHost: 'http://did-workshop.arcblock.co:8210/api',
    chainId: 'forge',
    chainToken: 'TBA',
    copyright: 'https://example-application/copyright',
    decimals: 16,
    description: 'Starter projects to develop web application on forge',
    icon: '/images/logo@2x.png',
    name: 'Forge Web Starter',
    path: 'https://arcwallet.io/i/',
    publisher: `did:abt:${wallet.address}`,
    subtitle: 'Starter projects to develop web application on forge',
  },
});

@arcblock/did-auth

Helper function to setup DID authentication support on a node.js web server

Apache-2.0
Latest version published 4 days ago

Package Health Score

55 / 100
Full package analysis