Next lesson playing in 5 seconds

  • Overview
  • Transcript

2.1 Authentication

If you want to perform protected actions on your site—such as creating or editing posts—you’ll need an authentication token. In this lesson, I’ll show you how to generate an OAuth token that allows us to use WPCOM.js.

Related Links

2.1 Authentication

Hello everyone, I am Reggie Dawson. Welcome to the Get Started with wpcom.js course for Tuts+. Now before we can get started using wpcom.js, we first must sign up for a account. There are many different options, but the free plan will work for our purposes. Go to and sign up for an account. Once you have set up your site, we then need to generate our token. This token is how we will gain access to use the API. In order to do this, we need to go to the developer area for If you aren't already logged in, all you need to do is login with your credentials. Once there, click on the My Apps link. And then after that, click on Create New Application. Once there, give your application a name and a description. Then in the website URL, we will add this address. We're going to use the node-wpcom-oauth to generate our token. This is a Node app that launches a small web server. And this is the address that will be used for it. Then in the redirect URLs we will use this address. Here, we are using another address that will be provided by the node app. This is where we will complete obtaining our token. Now in the JavaScript origins we will add this is the address that we will run our app from. Without this, any request will not work. Then add the answer to the math problem. Then in the type select Native and click Create. Once you have that, click on the title of your app so that you can see the OAuth information. Make sure to copy your client ID and client secret. After that, we will go to the node-wpcom-oauth project. Download the project and extract the contents of the zip file. Navigate to this folder in the command line. You will need to have Node.js installed for this to work. Then inside the node-wpcom-oauth master folder, run npm install. After that, navigate into the example folder. In this folder, we will also run npm install. After the packages are installed, open up the project in your editor. Inside the example folder there's a file named settingsexample.json. Rename this file the settings.json, and then open it so that we can make some changes. First add your client ID, then add your client secret. The redirection match will be used when we created our app in the developer area of Save the project and then go back to the command-line. You should still be in the example folder. Then run nodeindex.js. Once you run that command, navigate to the address you used as the site address when you set up your app. Localhost:3001. Once you do that, you should see the information in the settings.json file. Click on Let's get the code. This will take you to the authorization screen. Click Approve here. Then finally it will be ready to request the access token. Click on let's get it. Once you have that, save the access token and the blog ID. Now that we have our access token, that's all we will need to use all of the methods from wpcom.js. Not all of the operations we can use will require authentication, but making changes such as adding a blog post requires it. Now that we are authenticated, in the next video we will learn about the wpcom, and sight methods.

Back to the top