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

ogi-sdk

v1.0.5

Published

A comprehensive SDK for aggregating and accessing OpenGateway APIs, complete with versatile authentication methods.

Downloads

30

Readme

Getting Started Guide for SDK

Introduction

This SDK is designed for interactions with a specific API, offering functionalities like authentication, device location verification, and network information retrieval.

Prerequisites

  • Node.js environment.
  • Client credentials (client ID and client secret) for authentication.

Installation

  • If the SDK is available as an npm package, install it using npm install ogi-sdk

Initialization

import { OGISDK } from 'ogi-sdk';

// Initialize with your client credentials
const config = {
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    redirectUri: 'your-redirect-uri'
};

const sdk = new OGISDK(config);

Authentication

  • Two-legged OAuth for server-to-server communication:
const session = await sdk.auth.get2LeggedToken(['your-scope']);
  • Three-legged OAuth for user authentication:
const authUrl = await sdk.auth.get3LeggedAuthUrl({
    scopes: ['your-scope'],
    purpose: 'your-purpose'
});
// Redirect user to authUrl for authentication
  • Exchanging authorization code for a token:
const session = await sdk.auth.getTokenfromCode('authorization-code');

Request Client

  • Making requests using RequestClient:
const response = await sdk.requestClient.makeRequest('/your-api-endpoint', REQ_METHOD.GET, null, { session });

Device Location Verification

const location = {
    lat: 52.5200,
    lng: 13.4050,
    accuracy: 100,
    radius: 200,
    deviceId: 'your-device-id',
    deviceIdType: 'phoneNumber' // or 'ipv4Address', 'ipv6Address', 'networkAccessIdentifier'
};

const isLocationVerified = await sdk.verifyLocation(location);

SIM Swap

  • Retrieve the date of the last SIM swap for a given phone number:
const lastSimSwapDate = await sdk.getLastSimSwapDate('your-phone-number');
  • Check if a SIM swap has been performed during a specified past period:
const hasSimSwapped = await sdk.checkIfSimSwapped({
    phoneNumber: 'your-phone-number',
    maxAge: 24 // Hours to check in the past
});

Example Usage - CIBA

Here's an example showing how to use the SDK for device location verification and authentication:


async function main() {
    const sdk = new OGISDK({
        clientId: 'your-client-id',
        clientSecret: 'your-client-secret',
        redirectUri: 'your-redirect-uri'
    });
    
    // Authenticate and get a session token
    const authRes = await sdk.auth.cibaAuthLoginHint({
        purpose: ['purpose'],
        loginHint: 'hint'
    });

    const session = await sdk.auth.pollCibaToken(authRes.authReqId, 2);
    
    // Verify device location
    const location = {
        lat: 52.5200, // Latitude
        lng: 13.4050, // Longitude
        deviceId: '33699901031', // Device ID
        deviceIdType: 'phoneNumber' // Device ID type
    };
    
    const isLocationVerified = await sdk.verifyLocation(location);
    console.log('Is location verified:', isLocationVerified);

    // Check SIM Swap
    const lastSimSwapDate = await sdk.getLastSimSwapDate('123456789');
    console.log('Last SIM swap date:', lastSimSwapDate);

    const hasSimSwapped = await sdk.checkIfSimSwapped({
        phoneNumber: '123456789',
        maxAge: 24
    });
    console.log('Has SIM swapped in the last 24 hours:', hasSimSwapped);
}

main().catch(console.error);

Example Usage with get3LeggedAuthUrl (SERVER)

Here's an example showing how to use the SDK in case you are using the 3legged auth flow in development phase and need an existing public server for the redirect URL

    
const app = express();
const port = 3000;

// Initialize your SDK
const sdk = new OGISDK({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
});

// Redirect to Auth route
app.get('/redirectToAuth', async (req: Request, res: Response) => {
  const authURL = await sdk.auth.get3LeggedAuthUrl({
    scopes: ['openid'],
    purpose: ['dpv:FraudPreventionAndDetection:location-verification'],
});
  res.redirect(authURL);
});

// Callback route
app.get('/callback', async (req: Request, res: Response) => {
  const { code } = req.query; // Assuming your auth service redirects back with a "code" parameter

  if (!code) {
    return res.status(400).send('Authorization code is missing');
  }

  const session = await sdk.auth.getTokenfromCode(code);
  // Store the token in the session
  // call here to any other SDK API

  res.send('You are logged in');
});

app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`);
});