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

angular-oauth1-client

v0.1.12

Published

An OAuth1.0a client for AngularJS and Cordova/Ionic

Downloads

12

Readme

angular-oauth1-client

An OAuth1.0a client for AngularJS and Cordova/Ionic

Getting Started

Install this plugin with the dependencies

$ bower install angular-oauth1-client

Make sure to include these in your index.html:

For example, index.html:

<script src="lib/underscore/underscore-min.js"></script>
<script src="lib/cryptojslib/rollups/hmac-sha1.js"></script>
<script src="lib/cryptojslib/components/enc-base64-min.js"></script>
<script src="lib/angular-local-storage/dist/angular-local-storage.min.js"></script>
<script src="lib/angular-oauth1-client/dist/angular-oauth1-client.min.js"></script>

Make sure to install the cordova-plugin-inappbrowser plugin:

$ ionic plugin add cordova-plugin-inappbrowser

or

$ cordova plugin add cordova-plugin-inappbrowser

Usage

First you need to configure oauth1Client with your API data. Include oauth1Client as a dependency in your app definition:

angular.module('myModule', [
    'oauth1Client'
])

.config(function(oauth1ClientProvider) {
    oauth1ClientProvider.config({
        consumerKey: '~~YOUR~CONSUMER~KEY~~',
        consumerSecret: '~~YOUR~CONSUMER~SECRET~~',
        requestEndpoint: 'http://localhost/wordpress/oauth1/request',
        authorizeEndpoint: 'http://localhostwordpress/oauth1/authorize',
        accessEndpoint: 'http://localhost/wordpress/oauth1/access',
        oauthCallback: 'http://www.google.com'
    });
})

Then start the authorization flow in your controller. This will open up the InAppBrowser and ask the user to approve your app's access:

var authorizationProcess = oauth1Client.authorize();

After authorization, you are returned a wrapper around angular's $http that takes the same parameters and configs, but adds the OAuth authorization information to it:

authorizationProcess.then(function(authorizedHttp) {
    authorizedHttp({
        method: "POST",
        url: "http://localhost/wordpress/wp-json/users",
        data: {
            username: "User 2",
            name: "User 2",
            password: "User 2's Password",
            email: "[email protected]"
        }
    })
    .then(function(response) {
        alert("New user created!");
    }, function(response) {
        alert("Error! " + response.data);
    });
    authorizedHttp({
        method: "GET",
        url: "http://localhost/wordpress/wp-json/users/me"
    })
    .then(function(response) {
        alert("Success! " + JSON.stringify(response));
    },
    function(response) {
        alert("Error! " + JSON.stringify(response));
    });
});

Wordpress API Setup

If you are using the Wordpress WP-API you will need to set up the OAuth 1.0a server on your instance. See setup instructions at the WP REST API - OAuth 1.0a Server page.

Additional Information

Some things to note:

  1. WP-API Version - This plugin was originally built to use the Wordpress JSON API (WP-API) version 1. It has not been tested with version 2.
  2. CORS support - You will most likely need to enable CORS support on your Wordpress API. For development, a library by thenbrent will provide CORS support. As mentioned there, you will probably want to harden your server more in production.
  3. deviceready event - This plugin makes use of the Cordova InAppBrowser plugin. Cordova plugins only work when the deviceready event fires. See the plugin README for more details.
  4. Callback url - You may specify any callback url you like, as long as it actually resolves to a real website. There have been some issues with, for example, putting http://localhost when you aren't running anything on localhost or it isn't accessible from the iOS simulator.