Skip to content

Commit

Permalink
Changed to use callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
Resseguie committed May 9, 2014
1 parent 7cad132 commit f6a9294
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
Version numbers correspond to `bower.json` version

# 0.0.6

## Features
* Switched to passing callback function rather than two way binding with object in scope

## Bug Fixes

## Breaking Changes
* Not requires passing of callback function which receives a copy of the oauthUser object previously shared with two way data binding


# 0.0.5

## Features
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ Just add the following directive:

```html
<div drr-oauthio-login
data-oauth-user="oauthUser"
data-on-login="login(endpoint,user,provider,error)"
data-oauth-provider="github"
data-provider-icon="github-alt" // optional
data-oauthio-key="<your public OAuth.io key>">
</div>
```

You can extract information from the oauthUser after successful authentication such as:
After login, the onLogin callback function will be called. You can extract information from the returned user object after successful authentication such as:

```html
<h1>Logged in as {{oauthUser.user.name}}</h1>
<h1>Logged in as {{user.name}}</h1>
```

Our use oauthUser.endpoint to make manual OAuth calls to the provider API.
Use the returned endpoint object to make manual OAuth calls to the provider API.


## Testing

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-oauthio-login",
"version": "0.0.5",
"version": "0.0.6",
"authors": [
"David Resseguie <david@resseguie.com>"
],
Expand Down
23 changes: 16 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ <h1>angular-oauthio-login test</h1>

<div class="alert alert-danger" ng-show="keyError">You have to enter your OAuth.io public key for the test app to work!</div>

<h2 ng-show="oauthUser.user">Logged in user: {{oauthUser.user.name}}</h2>
<h2 ng-show="oauthUser.error">Error: {{oauthUser.error.message}}</h2>
<div ng-show="oauthUser"><a ng-click="oauthUser = null">Log out</a></div>


<div ng-repeat="(provider,icon) in providers">
<h2>{{provider}}</h2>
<div drr-oauthio-login
data-oauth-user="oauthUser"
data-on-login="login(endpoint,user,provider,error)"
data-oauth-provider="{{provider}}"
data-provider-icon="{{icon}}"
data-oauthio-key="{{oauthioKey}}">
</div>

<h2 ng-show="oauthUser.user">Logged in user: {{oauthUser.user.name}}</h2>
<h2 ng-show="oauthUser.error">Error: {{oauthUser.error.message}}</h2>
<div ng-show="oauthUser"><a ng-click="oauthUser = null">Log out</a></div>

</div>

<script src="bower_components/jquery/dist/jquery.js"></script>
Expand Down Expand Up @@ -71,7 +71,16 @@ <h2 ng-show="oauthUser.error">Error: {{oauthUser.error.message}}</h2>

$scope.$watch('oauthioKey',function(value){
$scope.keyError = (value == '<your public OAuth.io key here>');
})
});

$scope.login = function(endpoint,user,provider,error){
$scope.oauthUser = {
endpoint: endpoint,
user: user,
provider: provider,
error: error
};
}
}]);
</script>

Expand Down
5 changes: 3 additions & 2 deletions oauthio-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ angular.module('resseguie.angular-oauthio-login', [])
'</button>'+
'</div>',
scope : {
oauthUser : "=", // model to store the results
onLogin : "&", // callback function
oauthioKey : "@", // OAuthi.io public key
oauthProvider : "@", // OAuth provider to authenticate with
providerIcon : "@" // optional Font Awesome icon name to use
Expand All @@ -75,14 +75,15 @@ angular.module('resseguie.angular-oauthio-login', [])
oauthUser.user = result.user;
oauthUser.provider = scope.oauthProvider;
oauthUser.error = null;
scope.oauthUser = oauthUser;
scope.onLogin(oauthUser);
},function(error){
var oauthUser = {};
oauthUser.endpoint = null;
oauthUser.user = null;
oauthUser.error = error;
oauthUser.provider = scope.oauthProvider;
scope.oauthUser = oauthUser;
scope.onLogin(oauthUser);
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion oauthio-login.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f6a9294

Please sign in to comment.