Skip to content

ppeczek/angular-oauth1-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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

.config(function(oauth1ClientProvider) {
    oauth1ClientProvider.config({
        consumerKey: '',
        consumerSecret: '',
        requestEndpoint: '',
        authorizeEndpoint: '',
        accessEndpoint: '',
        oauthCallback: ''
    });
})

Then authorize your app in your controller:

var authorizationProcess = oauth1Client.authorize();

Finally do some requests to server:

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]"
        }
    })
        .success(function(data, status, headers, config) {
            alert("New user created!");
        })
        .error(function(data, status, headers, config) {
            alert("Error! " + data);
        });
    authorizedHttp({
        method: "GET",
        url: "http://localhost/wordpress/wp-json/users/me"
    })
        .success(function(data, status, headers, config) {
            alert(data);
        })
        .error(function(data, status, headers, config) {
            alert("Error! " + data);
        });
}

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%