All Projects → Patreon → Patreon Js

Patreon / Patreon Js

Licence: mit
Use the Patreon API via OAuth.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Patreon Js

Ueberauth
An Elixir Authentication System for Plug-based Web Applications
Stars: ✭ 1,259 (+1034.23%)
Mutual labels:  oauth
Nginx Openid Connect
Reference implementation of OpenID Connect integration for NGINX Plus
Stars: ✭ 96 (-13.51%)
Mutual labels:  oauth
Flask Oauthlib
YOU SHOULD USE https://github.com/lepture/authlib
Stars: ✭ 1,429 (+1187.39%)
Mutual labels:  oauth
Accounts
Fullstack authentication and accounts-management for Javascript.
Stars: ✭ 1,266 (+1040.54%)
Mutual labels:  oauth
Nextjs Starter
A starter project for Next.js with authentication
Stars: ✭ 1,313 (+1082.88%)
Mutual labels:  oauth
Ng Boot Oauth
oauth2 demo with angularjs and springboot
Stars: ✭ 99 (-10.81%)
Mutual labels:  oauth
Indielogin.com
Sign in with your domain name
Stars: ✭ 84 (-24.32%)
Mutual labels:  oauth
Ueberauth google
Google OAuth2 Strategy for Überauth.
Stars: ✭ 110 (-0.9%)
Mutual labels:  oauth
Ring Oauth2
OAuth 2.0 client middleware for Ring
Stars: ✭ 93 (-16.22%)
Mutual labels:  oauth
Flickr Sdk
Almost certainly the best Flickr API client in the world for node and the browser
Stars: ✭ 104 (-6.31%)
Mutual labels:  oauth
Docker Cloud Platform
使用Docker构建云平台,Docker云平台系列共三讲,Docker基础、Docker进阶、基于Docker的云平台方案。OpenStack+Docker+RestAPI+OAuth/HMAC+RabbitMQ/ZMQ+OpenResty/HAProxy/Nginx/APIGateway+Bootstrap/AngularJS+Ansible+K8S/Mesos/Marathon构建/探索微服务最佳实践。
Stars: ✭ 86 (-22.52%)
Mutual labels:  oauth
Androidoauth
A simple way to authenticate with Google and Facebook using OAuth 2.0 in Android
Stars: ✭ 88 (-20.72%)
Mutual labels:  oauth
Warden Github Rails
Use GitHub as authorization and more. Use organizations and teams as means of authorization by simply wrapping your rails routes in a block. Also useful to get a user's details through OAuth.
Stars: ✭ 100 (-9.91%)
Mutual labels:  oauth
Finagle Oauth2
OAuth2 Server-Side Provider for Finagle
Stars: ✭ 84 (-24.32%)
Mutual labels:  oauth
Docusign Node Client
The Official DocuSign Node.js Client Library used to interact with the eSign REST API. Send, sign, and approve documents using this client.
Stars: ✭ 108 (-2.7%)
Mutual labels:  oauth
Weixin
[READ ONLY] Subtree split of the SocialiteProviders/Weixin Provider (see SocialiteProviders/Providers)
Stars: ✭ 84 (-24.32%)
Mutual labels:  oauth
Vue Authenticate
Simple Vue.js authentication library
Stars: ✭ 1,350 (+1116.22%)
Mutual labels:  oauth
Spring Webmvc Pac4j
Security library for Spring Web MVC: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 110 (-0.9%)
Mutual labels:  oauth
Sample Spring Oauth2 Microservices
some examples that show basic and more advanced implementations of oauth2 authorization mechanism in spring-cloud microservices environment
Stars: ✭ 109 (-1.8%)
Mutual labels:  oauth
Bdboauth1manager
OAuth 1.0a library for AFNetworking 2.x
Stars: ✭ 101 (-9.01%)
Mutual labels:  oauth

patreon-js

Build State

Use the Patreon API via OAuth.

Setup

You'll need to register an OAuth client account to receive a client_id, client_secret and other info for use with this module.

Visit the OAuth Documentation Page while logged in as a Patreon creator on patreon.com to register your client.

Installation

Install with npm. You'll need to have Node.js installed.

npm install --save patreon

Usage

When you see 'pppp' replace pppp with the data you received setting up your OAuth account or otherwise suggested by the inline comments.

var url = require('url')
var patreon = require('patreon')
var patreonAPI = patreon.patreon
var patreonOAuth = patreon.oauth

// Use the client id and secret you received when setting up your OAuth account
var CLIENT_ID = 'pppp'
var CLIENT_SECRET = 'pppp'
var patreonOAuthClient = patreonOAuth(CLIENT_ID, CLIENT_SECRET)

// This should be one of the fully qualified redirect_uri you used when setting up your oauth account
var redirectURL = 'http://mypatreonapp.com/oauth/redirect'

function handleOAuthRedirectRequest(request, response) {
    var oauthGrantCode = url.parse(request.url, true).query.code

    patreonOAuthClient
        .getTokens(oauthGrantCode, redirectURL)
        .then(function(tokensResponse) {
            var patreonAPIClient = patreonAPI(tokensResponse.access_token)
            return patreonAPIClient('/current_user')
        })
        .then(function(result) {
            var store = result.store
            // store is a [JsonApiDataStore](https://github.com/beauby/jsonapi-datastore)
            // You can also ask for result.rawJson if you'd like to work with unparsed data
            response.end(store.findAll('user').map(user => user.serialize()))
        })
        .catch(function(err) {
            console.error('error!', err)
            response.end(err)
        })
}

If you're using babel or writing es2015 code:

import url from 'url'
import { patreon as patreonAPI , oauth as patreonOAuth } from 'patreon'

const CLIENT_ID = 'pppp'
const CLIENT_SECRET = 'pppp'
const patreonOAuthClient = patreonOAuth(CLIENT_ID, CLIENT_SECRET)

const redirectURL = 'http://mypatreonapp.com/oauth/redirect'

function handleOAuthRedirectRequest(request, response) {
    const oauthGrantCode = url.parse(request.url, true).query.code

    patreonOAuthClient
        .getTokens(oauthGrantCode, redirectURL)
        .then(tokensResponse => {
            const patreonAPIClient = patreonAPI(tokensResponse.access_token)
            return patreonAPIClient('/current_user')
        })
        .then(({ store }) => {
            // store is a [JsonApiDataStore](https://github.com/beauby/jsonapi-datastore)
            // You can also ask for result.rawJson if you'd like to work with unparsed data
            response.end(store.findAll('user').map(user => user.serialize()))
        })
        .catch(err => {
            console.error('error!', err)
            response.end(err)
        })
}

You can also reference the included server example.

Methods

var patreonOAuthClient = oauth(clientId, clientSecret)

Returns an object containing functions for fetching OAuth access tokens.

clientId The client id you received after setting up your OAuth account. clientSecret The client secret you received after setting up your OAuth account.

patreonOAuthClient.getTokens(redirectCode, redirectUri)

This makes a request to grab tokens needed for making API requests, and returns a promise.

redirectCode Use the code query param provided to your OAauth redirect route. redirectUri This should be the same redirect route you provided in the initial auth request.

The promise will be resolved with the parsed JSON containing a tokens response object, or will be rejected with an error message.

The tokens object will look something like this:

{
    access_token: 'access_token',
    refresh_token: 'refresh_token',
    expires_in: 'time_window',
    scope: 'users pledges-to-me my-campaign',
    token_type: 'Bearer'
}

You must pass tokens.access_token in to patreon for making API calls.

var client = patreon(accessToken)

Returns a function for making authenticated API calls.

client(pathname)

Returns a promise representing the result of the API call.

pathname API resource path like /current_user.

If the API call is successful, the promise will resolve with an object containing three pieces:

  • store: a JsonApiDataStore. This provides a nice, usable wrapper around the raw JSON:API response to easily access related resources and resource attributes.
  • rawJson: a JSON object in the JSON:API format, for advanced custom usage (say, parsing into your own JSON:API data store)
  • response: the actual fetch Response object, for the lowest level of response analysis

If the API call is unsuccessful, the promise will reject with an error.

API Resources

Routes

/current_user /current_user/campaigns /campaigns/${campaign_id}/pledges

Response Format

You can request specific related resources and or resource attributes that you want returned by our API, as per the JSON:API specification. The lists of valid includes and fields arguments are provided in patreon/schemas. For instance, if you wanted to request the total amount a patron has ever paid to your campaign, which is not included by default, you could do:

const { patreon, jsonApiURL } = require('patreon')
const pledge_schema = require('patreon/schemas/pledge')

const patreonAPIClient = patreon(access_token)
const url = jsonApiURL(`/current_user`, {
  fields: {
    pledge: [...pledge_schema.default_attributes, pledge_schema.attributes.total_historical_amount_cents]
  }
})
patreonAPIClient(url, callback)

Errata

Having additional scopes

The Patreon JS library uses a data store pattern for storing inflated objects from the returned results of API calls. In some cases, especially if you have been granted the scopes for being a multi-campaign client or are opted-in to some API beta programs, the JS client calling /current_user will fetch the current user's campaign, as well as all the patron users connected to that campaign.

This can result in the user store in the JS library having a larger list of users than expected for a call to /current_user, but the current user's user object will be in that list.

Example for finding the actual current user:

var patreon_response = patreon_client('/current_user').then(function(result) {
    user_store = result.store
    let data = result.rawJson
    const myUserId = data.data.id
    creator = user_store.find('user', myUserId)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].