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

reddit-oauth-pass-refresh

v1.2.1

Published

Reddit API wrapper with both OAuth and username/password authentication, updated to refresh even when username and password are used

Downloads

9

Readme

reddit-oauth-pass-refresh

NPM version

reddit-oauth-pass-refresh is a wrapper around the Reddit API providing both OAuth and password authentication.

It adds on to the original reddit-oauth by refreshing the access token after expiration even when authenticating with username and password.

Requirements

Installation

npm install reddit-oauth-pass-refresh

Documentation

Original documentation:

http://aiham.github.io/reddit-oauth

Usage

var RedditApi = require('reddit-oauth');
var reddit = new RedditApi({
    app_id: 'your_app_id',
    app_secret: 'your_app_secret',
    redirect_uri: 'your_app_redirect_uri'
});

// Authenticate with username/password
reddit.passAuth(
    'your_reddit_username',
    'your_reddit_password',
    function (success) {
        if (success) {
            // Print the access token we just retrieved
            console.log(reddit.access_token);
        }
    }
);

// Get the OAuth URL to redirect users to
// Scopes are defined here: https://github.com/reddit/reddit/wiki/OAuth2
reddit.oAuthUrl('some_state', 'identity');

// After the user is redirected back to us, grab the query string
// object and exchange it for a set of access and refresh tokens.
// Scope has to be identical as the one provided to oAuthUrl. Can
// change for each authentication attempt.
reddit.oAuthTokens(
    'some_state',
    request.query,
    function (success) {
        // Print the access and refresh tokens we just retrieved
        console.log(reddit.access_token);
        console.log(reddit.refresh_token);
    }
);

// Returns true if access token exists
reddit.isAuthed();

// Force a refresh of the access token using the refresh token
reddit.refreshToken(
    function (success) {
        // Print the access token we just retrieved
        console.log(reddit.access_token);
    }
);

// Call authenticated GET endpoint
reddit.get(
    '/api/v1/me',
    {},
    function (error, response, body) {
        console.log(error);
        console.log(body);
    }
);

// Call authenticated GET listing endpoint with easy pagination
reddit.get(
    '/user/aihamh/submitted',
    {},
    function (error, response, body, next) {
        console.log(error);
        console.log(body);

        // next is not null, therefore there are more pages
        if (next) {
            next(); // Invoke next to retrieve the next page
        }
    }
);

// Call authenticated POST endpoint
reddit.post(
    '/api/comment',
    {
        api_type: 'json',
        text: 'Hello World!',
        thing_id: 'abc123'
    },
    function (error, response, body) {
        console.log(error);
        console.log(body);
    }
);

Run Tests

Tests written with mocha.

Copy test/config.template.json to test/config.json and add your own app and user credentials. Then run:

npm test

Generate Documentation

Documentation can be generated with jsdoc by running:

npm run docs