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

meigetsuidlib

v1.0.6

Published

Meigetsu ID Request Wrapper Library

Downloads

14

Readme

Meigetsu ID API Library

このライブラリは、Meigetsu IDのラッパーライブラリです。

APIの利用には、Meigetsu IDのクライアントIDとクライアントシークレット(アプリケーションの種類がConfidentialの場合)が必要になります。

これらは、Meigetsu IDに登録後、アプリケーションの登録を行うことで実施することができます。

インストール方法

ライブラリは不具合修正やMeigetsu IDのアップデートに基づいて更新されるため、特段何か問題が無い限りは常に最新のものを使用して下さい。

最新のバージョン番号はこちらでご確認下さい。

NPMを使用する場合

下記コマンドを実行して下さい。

なお、型データはライブラリに同梱されておりますので、別途インストールする必要はありません。

npm install meigetsuidlib --save

HTMLのscriptタグを使って呼び出す場合

下記をheadに追加して下さい。

<script src="https://library.meigetsu.jp/meigetsuid/(バージョン番号)/index.js"></script>

アクセストークンの取得方法(リフレッシュトークンが無い場合)

1. GetAuthorizationIDで認可IDを取得する

アプリケーションの種類がConfidentialの場合

import { GetAuthorizationID } from 'meigetsuidlib';

const AuthorizationID = await GetAuthorizationID(
    {
        client_id: '<input your app client id>',
        client_secret: '<input your app client secret>',
        redirect_uri: '<input your app entried redirect uri>',
    },
    ['user.read', 'user.write'],
    '<input PKCE hashed value>',
    '<input PKCE hash method>'
);

アプリケーションの種類がPublicの場合

import { GetAuthorizationID } from 'meigetsuidlib';

const AuthorizationID = await GetAuthorizationID(
    { client_id: '<input your app client id>', redirect_uri: '<input your app entried redirect uri>' },
    ['user.read', 'user.write'],
    '<input PKCE hashed value>',
    '<input PKCE hash method>'
);

認可コードの取得方法について

Meigetsu IDはRFC 6749に定義する認可コードフローを採用しております。

そのため、認可エンドポイントへのリクエストの方法で認可IDを取得することもできます。

URLの生成についてはこちらで行うことができます。

Scopeについて

GetAuthorizationIDの第2引数は、scopeを配列で指定する形となっています。

指定可能なScopeについてはこちらのページのAuthorizeのボタンを押すとScopesのセクションをご確認下さい。

なお、Scopeについてはアプリケーションの種類やデベロッパーのアカウント種別によって使えるものが異なります。

2. Meigetsu IDの認可ページへリダイレクトし、ユーザーに認可を要求する

https://idportal.meigetsu.jp/oauthへリダイレクトしていただく形となります。

この時、クエリパラメーターauth_idを加える必要があります。

auth_idの値は、GetAuthorizationIDの戻り値です。

location.href = 'https://idportal.meigetsu.jp/oauth?auth_id=' + AuthorizationID;

ユーザーが認可すると、Meigetsu IDはクエリパラメーターとしてauth_code(認可コード)を付与し、事前に登録されたリダイレクトURLに自動的にリダイレクトします。

3. アクセストークンを取得する

クエリパラメーターauth_codeの値を取得し、これとcode_challengeGetAuthorizationIDの第3引数)の元の値をGetTokenに渡します。

const token = await GetToken('<input auth code>', '<input code verifier>');

GetTokenの戻り値はオブジェクト(JSON)となっており、形式は、下記の通りです。

{
    "token_type": "Bearer",
    "access_token": "access token(text length: 256)",
    "refresh_token": "refresh token(text length: 256)",
    "expires_at": {
        "access_token": "access token expires datetime(ISO8601 compliant)",
        "refresh_token": "refresh token expires datetime(ISO8601 compliant"
    }
}

アクセストークンの取得方法(リフレッシュトークンがある場合)

リフレッシュトークンをGetTokenの第1引数に渡します。

この時、第2引数は入れないで下さい。

const token = await GetToken('<input refresh token>');

GetTokenの戻り値の型および形式は、アクセストークンの取得方法(リフレッシュトークンがある場合)のアクセストークンを取得するに記載のものと同じです。