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

pocket-auth-cli

v1.0.0

Published

Get a Pocket access token via the command line

Downloads

6

Readme

pocket-auth

A small node.js library for authenticating with the Pocket API.

Build Status

pocket-auth requires a minimum NodeJS version of 7.6

The Pocket Auth Flow

Pocket use a modified oauth flow for gaining an access token that looks like the following:

  • Fetch a request_token by making a POST request to https://getpocket.com/v3/oauth/request
  • Open a browser to https://getpocket.com/auth/authorize?request_token={request_token}&redirect_uri={redirect_uri}, where redirect_uri the the URL to redirect to afterwards.
    • In a normal OAuth flow, the URL will contain an access token as a GET parameter at this point
    • In Pocket's flow, they redirect to redirect_uri exactly as it is provided. They do not add an access token (you request that separately later)
    • This means that you can use https://google.com as your redirect URL
  • Once the user has clicked Approve, you can exchange your request_token for an access token by making a POST request to https://getpocket.com/v3/oauth/authorize

Example Usage

You can use this library with either a Promise or a Callback based interface

async/await

async function main() {
    try {
        var auth = require("pocket-auth");

        var consumerKey = "your-consumer-key";
        var redirectUri = "https://google.com";

        let code = await auth.fetchToken(consumerKey, redirectUri, {});
        let uri = auth.getRedirectUrl(code.code, redirectUri);
        console.log("Visit the following URL and click approve in the next 10 seconds:");
        console.log(uri);

        setTimeout(async function(){
            try {
                let r = await auth.getAccessToken(consumerKey, code.code);
                console.log(r);
            } catch (err) {
                console.log("You didn't click the link and approve the application in time");
            }
        }, 10000);
    } catch (err) {
        console.log(err);
    }
}

main();

Callback

var auth = require("pocket-auth");

var consumerKey = "your-consumer-key";
var redirectUri = "https://google.com";

auth.fetchToken(consumerKey, redirectUri, {}, function(err, code) {
    let uri = auth.getRedirectUrl(code.code, redirectUri);
    console.log("Visit the following URL and click approve in the next 10 seconds:");
    console.log(uri);

    setTimeout(async function(){
        auth.getAccessToken(consumerKey, code.code, function(err, r) {
            if (err) {
                console.log("You didn't click the link and approve the application in time");
                return;
            }

            console.log(r);
        });
    }, 10000);
});