Skip to content

Automattic/wpcom-oauth-cors

Folders and files

Image for: Folders and files
NameName
Last commit message
Last commit date

Latest commit

Image for: Latest commit
 

History

Image for: History
78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image for: Repository files navigation

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

Image for: 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

Image for: 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

Image for: Test
  • Compile testing js file
> make test
  • Go to test/ folder

  • Run web server (using serve for instance)

  • Open index.html with a browser

About

Image for: About

Implicit OAuth client-side module

Resources

Stars

Watchers

Forks

Packages

Image for: Packages 0
No packages published

Contributors 6

Image for: Contributors 6

Languages

Image for: Languages