wpcom-oauth-cors

1.0.2-beta • Public • Published

wpcom-oauth-cors

WordPress.com implicit OAuth2 client-side authorization module.

The server-side (Node.js) counterpart to this module is wpcom-oauth.

> npm install wpcom-oauth-cors

How to use

var wpcomOAuth = require('wpcom-oauth-cors')('<client-id>');
 
// get auth object
wpcomOAuth.get(function(auth){
  // Here, your token is available as auth.access_token
  // e.g.:
  // var wpcom = require('wpcom');
  // var wpc = wpcom(auth.access_token);
});
 
// clean stored token
wpcomOAuth.clean();
 
// get stored token
var auth = wpcomOAauth.token();

API

wpcomOAuth(client_id, params)

Create a wpcomOAuth instance giving client_id (String) and optional parameters object

params:

  • redirect
  • blog
  • response_type
  • scope
  • state

wpcomOAuth.get(fn)

wpcomOAuth.clean()

wpcomOAuth.request()

wpcomOAuth.reset()

wpcomOAuth.token()

Example

This snippet will log a posts array from site with id 123456.

var wpcom = require('wpcom');
var wpcomOAuth = require('wpcom-oauth-cors')('<client-id>');
 
// get auth object
wpcomOAuth.get(function(auth){
  // Here, your token is available as auth.access_token
  var wpc = wpcom( auth.access_token );
  var mySite = wpc.site( 123456 );
  mySite.postsList({ number: 50, fields: "author,URL,title,geo" }, function(err, list) {
      console.log( list );
  });
});
 

Test

  • Compile testing js file
> make test
  • Go to test/ folder

  • Run web server (using serve for instance)

  • Open index.html with a browser

Readme

Keywords

none

Package Sidebar

Install

npm i wpcom-oauth-cors

Weekly Downloads

2,045

Version

1.0.2-beta

License

none

Unpacked Size

128 kB

Total Files

11

Last publish

Collaborators

  • porada
  • imranh920
  • gmjuhasz
  • rcarvalho
  • briowill
  • bgrgicak
  • dhenridev
  • daledupreez-a8c
  • jeherve
  • yuliyan
  • micbosia8c
  • jeremy.yip
  • wpvip-bot
  • etobiesen
  • kzoschke
  • brunobasto
  • kat3samsin
  • fmfernandes
  • newspack
  • robertsreberski_a8c
  • msurdi-a8c
  • chihsuan
  • manzoorwanijk
  • rjchow
  • andrea-sdl
  • scjr
  • spsiddarthan
  • t2dw4t
  • ehg_
  • wwa
  • sirreal
  • elazzabi
  • royho
  • luismulinari
  • macbre
  • mjangda
  • matticbot
  • a8c
  • blowery
  • noahtallen
  • hanifn
  • sgomes
  • tyxla
  • saroshaga
  • parkcityj
  • nejclovrencic
  • sirbrillig
  • chriszarate
  • robersongomes
  • johngodley
  • nylen
  • tootallnate
  • retrofox