<commit_before>jquery-cordova-oauth2
=====================

__jQuery plugin for doing Oauth2 login in a Cordova App__

This jquery plugin can be used to perform __Oauth2__ login in __Cordova__ app, it uses Cordova In-App-Browser to perform Oauth2 login flow and returns `access_token` or `error` in callback, along with actual response from the Oauth2 service.

Features
-
- Supports Oauth2 authorization code grant flow (server explicit)
- Supports Oauth2 implicit grant flow (client implicit)

Usage
-

```javascript
    $.oauth2({
        auth_url: '',           // required
        response_type: '',      // required  - "code"/"token"
        token_url: '',          // required for "code"
        logout_url: '',         // recommended if available
        client_id: '',          // required
        client_secret: '',      // required
        redirect_uri: '',       // required - any dummy url http://www.yourcompany.com
        other_params: {}         // optional params object for scope, state, ...
    }, function(token, response){
        // do something with token or response
    }, function(error, response){
        // do something with error object
    }); 
```

__Example Oauth2 Calls:__

__1) Google Oauth2 (Authorization code grant):__
This example show how to make Google Oauth2 call, notice the `scope` parameter is sepcified in the `other_params` option as an object. The first callback function will return the `access_token` which can be passed to another function to save and make other API calls. The second callback function handle any errors.

```javascript
    $.oauth2({
        auth_url: 'https://accounts.google.com/o/oauth2/auth',
        response_type: 'code',
        token_url: 'https://accounts.google.com/o/oauth2/token',
        logout_url: 'https://accounts.google.com/logout',
        client_id: 'CLIENT-ID-FROM-GOOGLE',
        client_secret: 'CLIENT-SECRET-FROM-GOOGLE',
        redirect_uri: 'http://www.yourwebsite.com/oauth2callback',
        other_params: {scope:'profile'}
    }, function(token, response){
        makeAPICalls(token);
    }, function(error, response){
        alert(error);
    }); 
```

__2) Facebook Oauth2 (Implicit grant):__
Notice that `token_url` is not required for Implicit grant and `logout_url` is not specified since facebook does not not have a logout url. Facebook also required a special `display` parameter to be passed in the URL, this is specified in the `other_params`.

```javascript
    $.oauth2({
        auth_url: 'https://www.facebook.com/dialog/oauth',
        response_type: 'token',
        client_id: 'CLIENT-ID-FROM-FACEBOOK',
        client_secret: 'CLIENT-SECRET-FROM-FACEBOOK',
        redirect_uri: 'http://www.yourwebsite.com/oauth2callback',
        other_params: {scope: 'basic_info', display: 'popup'}
    }, function(token, response){<commit_msg>updated info about client_secret<commit_after>jquery-cordova-oauth2
=====================

__jQuery plugin for doing Oauth2 login in a Cordova App__

This jquery plugin can be used to perform __Oauth2__ login in __Cordova__ app, it uses Cordova In-App-Browser to perform Oauth2 login flow and returns `access_token` or `error` in callback, along with actual response from the Oauth2 service.

Features
-
- Supports Oauth2 authorization code grant flow (server explicit)
- Supports Oauth2 implicit grant flow (client implicit)

  _[Implicit grant is recomended for Cordova apps since it does not require app to store client_secret]_

Usage
-

```javascript
    $.oauth2({
        auth_url: '',           // required
        response_type: '',      // required  - "code"/"token"
        token_url: '',          // required for response_type ="code"
        logout_url: '',         // recommended if available
        client_id: '',          // required
        client_secret: '',      // required for response_type ="code"
        redirect_uri: '',       // required - any dummy url http://www.yourcompany.com
        other_params: {}         // optional params object for scope, state, ...
    }, function(token, response){
        // do something with token or response
    }, function(error, response){
        // do something with error object
    }); 
```

__Example Oauth2 Calls:__

__1) Google Oauth2 (Authorization code grant):__
This example show how to make Google Oauth2 call, notice the `scope` parameter is sepcified in the `other_params` option as an object. The first callback function will return the `access_token` which can be passed to another function to save and make other API calls. The second callback function handle any errors.

```javascript
    $.oauth2({
        auth_url: 'https://accounts.google.com/o/oauth2/auth',
        response_type: 'code',
        token_url: 'https://accounts.google.com/o/oauth2/token',
        logout_url: 'https://accounts.google.com/logout',
        client_id: 'CLIENT-ID-FROM-GOOGLE',
        client_secret: 'CLIENT-SECRET-FROM-GOOGLE',
        redirect_uri: 'http://www.yourwebsite.com/oauth2callback',
        other_params: {scope:'profile'}
    }, function(token, response){
        makeAPICalls(token);
    }, function(error, response){
        alert(error);
    }); 
```

__2) Facebook Oauth2 (Implicit grant):__
Notice that `token_url` and `client_secret` is not required for Implicit grant and `logout_url` is not specified since facebook does not not have a logout url. Facebook also required a special `display` parameter to be passed in the URL, this is specified in the `other_params`.

```javascript
    $.oauth2({
        auth_url: 'https://www.facebook.com/dialog/oauth',
        response_type: 'token',
        client_id: 'CLIENT-ID-FROM-FACEBOOK',
        redirect_uri: 'http://www.yourwebsite.com/oauth2callback',
        other_params: {scope: 'basic_info', display: 'popup'}
    }, function(token, response){
{'fraction_non_alphanumeric': 0.11291980808773132, 'fraction_numerical': 0.006854009595613434, 'mean_word_length': 3.0591098748261474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3241267', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1632, 'n_words': 546}