simple-oauth1a
v1.0.2
Published
OAuth1a made simple, zero dependencies
Downloads
23
Readme
simple-oauth1a
Simple, zero-dependency package for interfacing with OAuth1a providers
Usage
1 Create client
const client = new OAuth1aClient({
apiKey: "", // sometimes called consumer key
apiSecret: "", // sometimes called consumer secret
callbackUrl: "https://your-app.com/callback",
endpoints: {
// URL of the provider's authorize endpoint
authorize: "https://some-oauth-provider.com/oauth/authorize",
// URL of the provider's request endpoint endpoint
requestToken: "https://some-oauth-provider.com/oauth/request_token",
// URL of the provider's access token endpoint
getToken: "https://some-oauth-provider.com/oauth/access_token",
},
// It is possible to override the nonce generation with the getNonce param. Default is randomBytes(32).toString("base64url")
});2 Generate request token
const {
oauth_token, // Raw token
authorizeUrl // Full authorization URL, the user needs to navigate to this site in their browser
} = await client.requestToken();3 Resolve access token
const {
oauthToken, // a.k.a. access token
oauthTokenSecret // a.k.a. access token secret
} = await client.getToken({
oauthToken: "", // The value comes from a query param on your callback endpoint
oauthVerifier: "", // The value comes from a query param on your callback endpoint
});4 Use the fetch method for any provider-specific endpoints
[!TIP] This method is API-compatibile with the standard
fetchmethod
const resp = await client.fetch("https://some-oauth-provider.com/users/me", {
oauthToken: "", // resolved token from `client.getToken`
oauthTokenSecret: "", // resolved token secret from `client.getToken`
});
const user = await resp.json();