Skip to content

Instantly share code, notes, and snippets.

View theBoEffect's full-sized avatar

Bo Motlagh theBoEffect

View GitHub Profile
@theBoEffect
theBoEffect / account-user-create-and-push.js
Created July 31, 2022 19:55
Programmatically Creating an Account and User in NATS.io Using Node
// using require rather than import to make this simple for a standard javascript example
const {connect, StringCodec, credsAuthenticator} = require('nats');
const {encodeAccount, encodeUser} = require('nats-jwt');
const {createAccount, createUser, fromSeed} = require('nkeys.js');
// The Seed representing the Operator - you'll need this to sign new Accounts. Notice it starts with 'SO'
const opSeed = 'SOA...';
// The JWT representing the User from the System Account (Step 4)
const sysJwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJlZDI1NTE5LW5rZXkifQ...';
// The Seed representing the User from the System Account (Step 3). Notice it starts with 'SU'
@theBoEffect
theBoEffect / validateToken.js
Created March 9, 2022 20:33
An example of validating an United Effects Core OIDC token with node and passport
import jwt from 'jsonwebtoken';
import qs from 'querystring';
import jkwsClient from 'jwks-rsa';
import axios from 'axios';
import Boom from '@hapi/boom';
import passport from "passport";
import {Strategy as BearerStrategy} from "passport-http-bearer";
// CORE is the domain + authGroup of the Core EOS OIDC connection (aka issuer)
const CORE = process.env.CORE_EOS;