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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sso-sumut-client

v1.0.0

Published

Official client library for SSO SUMUT authentication using JWT

Readme

SSO Sumut Client Package

Package ini memudahkan integrasi aplikasi Node.js (backend) dan React.js (frontend) dengan layanan SSO BPS Provinsi Sumatera Utara.

Instalasi

Karena package ini bersifat lokal (belum dipublish ke npm registry), Anda bisa menginstallnya dengan menunjuk ke foldernya secara langsung, atau copy-paste folder ini ke proyek Anda.

npm install ./path/to/sso-sumut-client

Atau jika Anda menggunakan folder ini sebagai modul lokal, cukup require dari path-nya.

Konfigurasi (Backend)

Anda memerlukan 3 kunci rahasia yang HARUS SAMA dengan yang ada di server SSO:

  1. Encryption Key (32 bytes)
  2. IV (Initialization Vector, 16 bytes)
  3. JWT Secret

Simpan kunci-kunci ini di .env file aplikasi Anda. JANGAN PERNAH menyimpan kunci ini di kode frontend (React/Browser).


1. Penggunaan di Frontend (React.js / Next.js)

Untuk frontend, package ini menyediakan helper getLoginUrl yang aman dijalankan di browser (tanpa dependensi Node.js).

Import Helper

import { getLoginUrl } from 'sso-sumut-client/frontend';

Contoh Komponen Tombol Login (Copy-Paste)

Anda bisa langsung menggunakan komponen React berikut:

import React from 'react';
import { getLoginUrl } from 'sso-sumut-client/frontend';

// Ganti dengan URL SSO yang benar
const SSO_SERVER_URL = "https://otp-dev.bps.web.id"; 

const SsoLoginButton = () => {
    const handleLogin = () => {
        // Halaman di aplikasi Anda yang akan menerima token setelah login sukses
        // Contoh: http://localhost:3000/callback
        const currentUrl = window.location.origin + "/callback";
        
        // Generate URL login
        const loginUrl = getLoginUrl(SSO_SERVER_URL, currentUrl);
        
        // Redirect user
        window.location.href = loginUrl;
    };

    return (
        <button 
            onClick={handleLogin}
            style={{
                padding: '10px 20px',
                backgroundColor: '#007bff',
                color: 'white',
                border: 'none',
                borderRadius: '5px',
                cursor: 'pointer',
                fontSize: '16px',
                fontWeight: 'bold'
            }}
        >
            Login dengan SSO BPS Sumut
        </button>
    );
};

export default SsoLoginButton;

2. Penggunaan di Backend (Node.js)

Gunakan index.js (default import) untuk memverifikasi token.

const ssoClient = require('sso-sumut-client');

// Konfigurasi (sebaiknya ambil dari process.env)
const config = {
    encryptionKey: '12345678901234567890123456789012', 
    iv: '1234567890123456',                         
    jwtSecret: 'rahasia_negara'                     
};

// Contoh Express Middleware
app.get('/callback', (req, res) => {
    const { token } = req.query; // SSO akan mengirim token ke URL callback

    try {
        // Verifikasi token
        const userData = ssoClient.verify(token, config);
        console.log("User valid:", userData);
        
        // Login sukses, buat session untuk user di aplikasi Anda
        req.session.user = userData;
        res.redirect('/dashboard');
        
    } catch (error) {
        console.error("Login gagal:", error.message);
        res.status(401).send("Autentikasi Gagal");
    }
});

Struktur Data User

Jika verifikasi berhasil, fungsi verify akan mengembalikan objek user dengan struktur seperti:

  • username
  • nama_lengkap
  • email
  • nip_lama / nip_baru
  • kode_satker
  • Dll.

Troubleshooting

  • Decryption failed: Pastikan encryptionKey dan iv sama persis dengan yang digunakan server SSO.
  • JWT Verification failed: Pastikan jwtSecret sesuai.
  • Token expired: Minta user login ulang jika token sudah kadaluarsa.