🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

github.com/mheap/pocket-auth

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/mheap/pocket-auth

v1.2.4
Source
Go
Version published
Created
Source

pocket-auth

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

pocket-auth requires a minimum NodeJS version of 6.0

The Pocket Auth Flow

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

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);
});

FAQs

Package last updated on 07 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts