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

@creator.co/module-identity-client

v1.1.8

Published

- ![npm](https://img.shields.io/npm/dy/@creator.co/module-identity-client) ![npm](https://img.shields.io/npm/v/@creator.co/module-identity-client) ![npm (tag)](https://img.shields.io/npm/v/@creator.co/module-identity-client/latest) ![Libraries.io dependen

Downloads

330

Readme

IDM Client - Module Identity NodeJS/Browser client.

  • npm npm npm (tag) Libraries.io dependency status for latest release, scoped npm package
  • GitHub commit activity
  • GitHub last commit
  • GitHub top language
  • GitHub code size in bytes

Documentation available here

Utilization

Client

    import IDM from '@creator.co/module-identity-client'
    const client = new IDM({
        apiEndpoint: 'http://localhost:8080', # - The API endpoint for IDM
        --OR--
        apiEndpoint: 'https://auth.dev.creator.co', # - The API endpoint for IDM
        externalAuth: false, # - When enabled, you should set externalAuthDomain, so all login calls are made on the externalAuthDomain and replied back with an SSO code which allows the foreign client to maintain a session while authenticated.
        disableLogs: false, # - Flag to disable logging
        roles: {
            admin: 'admin',
            brand: 'brand',
            agency: 'agency',
            creator: 'creator',
            user: 'user',
        },
    })

Login

Login can be done with the following (below). JWT will be automatically managed by this client and injected into any API calls to idm service but also renew it when it's about to expire or expired.

    const login = await client.authenticator.login('[email protected]', 'test').catch((e) => {
        showError(login.err)
    })
    if (login.token) {
        // success
        const userId = a?.metadata?.user?.[0]?.userId
        showSuccess(userId)
    }

Registration

Registration and other calls that require recaptchaToken can only be used with browser access. For dev purposes, we can use the HTML on examples/recaptcha.html to generate a new one and manually add into the request we are trying to test. Since Google recaptcha whitelists a domain and we added localhost:8000 to it, you can server the html file using, cd examples && python3 -m http.server and open http://localhost:8000/recaptcha.html in the browser. You should be present with an alert and when 'OK' is clicked, the recaptcha token should be printed in the console.

Disclaimer: The provided example already includes the publicly accessible recaptcha client. Secret is reserved for the API and should never be public. Disclaimer 2: At the moment, dev and production, do share the same google recaptcha keys for simplicity.

    const registrationResponse = await client.registration.register({
        recaptchaToken: '<your-recaptcha-token>',
        email: '[email protected]',
        firstName: 'First',
        lastName: 'Last',
        password: 'SecurePassword123',
    });
    ....---- Gets code through email ----....
    // This call will confirm user and if goes good, automatically login :p
    const loginResponse = await client.registration.confirmRegistrationAndLogin(
        '[email protected]',
        '<confirmation-code-on-email>',
        '<recaptcha-token>'
    ).catch((e) => {
        showError(login.err)
    })
    if (login.token) {
        // success
        const userId = a?.metadata?.user?.[0]?.userId
        showSuccess(userId)
    }

Authorization Module - Server side

The IDM client now supports a robust authorization system using the Authorizer class. This class allows you to manage access control based on JWT tokens, API keys, and customizable access levels and ACLs.

Here’s how you can utilize the Authorizer in your application:

import IDM from '@creator.co/module-identity-client';

// Configuration for Authorizer
const permissions = {
    accessLevel: 'user',  // Access level can be 'admin', 'brand', 'agency', 'creator', 'user', or custom
    acls: [{ componentId: 'component1', level: 'read', targetId: '*' }], // ACLs to define specific permissions
};

const config = {
    cache: { host: 'localhost', port: 6379 }, // Redis cache configuration
};

const creds = {
    authorization: 'Bearer your_jwt_token_here', // Or use apiKey: 'your_api_key_here' for API key authentication
};

// Instantiate the Authorizer
const authorizer = new IDM.Authorizer(permissions, config, creds);

// Authenticate and Authorize
(async () => {
    const authResult = await authorizer.authenticate();
    if (authResult === true) {
        console.log('User authenticated and authorized');
    } else {
        console.error('Authentication/Authorization failed:', authResult);
    }
})();

// Additional utility functions
const canManageUser = authorizer.canManageUser('userId');
const canUseBrand = await authorizer.canUseBrand('brandId');
const userId = authorizer.getUserId();

Features of the Authorizer:

  • Authentication: Supports JWT and API key-based authentication.
  • Authorization: Manages access levels and ACLs to determine permissions.
  • Utility Functions: Includes functions to check if a user can manage other users or access certain resources.

Roles Supported:

  • Admin
  • Brand
  • Agency
  • Creator
  • User

This system ensures that only users with the appropriate permissions can access specific resources or perform certain actions within your application.