Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'origin/master'

  • Loading branch information...
commit f99f69873bcee68d8ca364aa34d0275b3748298e 2 parents 26fb645 + 719690e
@bnoguchi authored
View
27 README.md
@@ -44,6 +44,8 @@ So far, `everyauth` enables you to login via:
<tr> <td> <img src="https://github.com/bnoguchi/everyauth/raw/master/media/gowalla.ico" style="vertical-align:middle"> Gowalla <td> <a href="https://github.com/andykram">Andrew Kramolisch</a>
<tr> <td> <img src="https://github.com/bnoguchi/everyauth/raw/master/media/tripit.png" style="vertical-align:middle"> TripIt <td> <a href="https://github.com/pirxpilot">Damian Krzeminski</a>
<tr> <td> <img src="https://github.com/bnoguchi/everyauth/raw/master/media/500px.ico" style="vertical-align:middle"> 500px <td> <a href="https://github.com/dannyamey">Danny Amey</a>
+ <tr> <td> <img src="https://github.com/bnoguchi/everyauth/raw/master/media/mixi.ico" style="vertical-align:middle"> ufssf
+ <td> <a href="https://github.com/ufssf">ufssf</a>
</tbody>
<tbody id=misc>
<tr> <td> <img src="https://github.com/bnoguchi/everyauth/raw/master/media/box.ico" style="vertical-align:middle"> Box.net <td>
@@ -1686,6 +1688,31 @@ connect(
).listen(3000);
```
+### mixi OAuth2
+
+First, register an app [on mixi](http://developer.mixi.co.jp).
+
+```javascript
+var everyauth = require('everyauth')
+ , connect = require('connect');
+
+everyauth.mixi
+ .appId('YOUR CONSUMER KEY HERE')
+ .appSecret('YOUR CONSUMER SECRET HERE')
+ .display('pc') //specify device types of access: See http://developers.mixi.co.jp/
+ .scope('r_profile') //specify types of access: See http://developers.mixi.co.jp/
+ .findOrCreateUser( function (session, accessToken, accessTokenExtra, mixiUserMetadata) {
+ // find or create user logic goes here
+ // Return a user or Promise that promises a user
+ // Promises are created via
+ // var promise = this.Promise();
+ })
+ .redirectPath('/');
+
+var routes = function (app) {
+ // Define your routes here
+};
+```
### OpenID protocol
View
5 example/conf.js
@@ -95,4 +95,9 @@ module.exports = {
consumerKey: 'Enter your consumer key here'
, consumerSecret: 'Enter your consumer secret here'
}
+ , mixi: {
+ consumerKey: 'Enter your consumer key here'
+ , consumerSecret: 'Enter your consumer secret here'
+ , scope: 'r_profile'
+ }
};
View
12 example/server.js
@@ -358,6 +358,18 @@ everyauth['500px']
})
.redirectPath('/');
+everyauth
+ .mixi
+ .appId(conf.mixi.consumerKey)
+ .appSecret(conf.mixi.consumerSecret)
+ .scope(conf.mixi.scope)
+ .display('pc')
+ .findOrCreateUser( function (session, accessToken, accessTokenExtra, mixiUserMetadata) {
+ return usersByFbId[mixiUserMetadata.id] ||
+ (usersByFbId[mixiUserMetadata.id] = addUser('mixi', mixiUserMetadata));
+ })
+ .redirectPath('/');
+
var app = express.createServer(
express.bodyParser()
, express.static(__dirname + "/public")
View
6 example/views/home.jade
@@ -75,6 +75,9 @@
img(src='http://www.tripit.com/images/logos/logo_90x40_trans.gif', title='Login with TripIt')
#500px-login
a(href='/auth/500px', style='border: 0px') Login with 500px
+ #mixi-login
+ a(href='/auth/mixi', style='border: 0px')
+ img(src='http://mixi.co.jp/press/images/thumb_press_def.gif', title='Login with mixi')
#openid-login
form#openid(action='/auth/openid')
label(for='openid_identifier') OpenID Identifier: &nbsp;
@@ -154,5 +157,8 @@
- if (everyauth['500px'])
h3 500px User Data
p= JSON.stringify(everyauth['500px'].user)
+ - if (everyauth.mixi)
+ h3 mixi User Data
+ p= JSON.stringify(everyauth.mixi.user)
h3
a(href='/logout') Logout
View
73 lib/modules/mixi.js
@@ -0,0 +1,73 @@
+var oauthModule = require('./oauth2')
+ , url = require('url');
+
+var mixi = module.exports =
+oauthModule.submodule('mixi')
+ .configurable({
+ scope: 'specify types of access: See http://developers.mixi.co.jp/'
+ , display: 'specify types of access: See http://developers.mixi.co.jp/'
+ })
+
+ .apiHost('https://api.mixi-platform.com/2')
+ .oauthHost('https://secure.mixi-platform.com/2/token')
+
+ .accessTokenPath('https://secure.mixi-platform.com/2/token')
+
+ .authPath('https://mixi.jp/connect_authorize.pl')
+
+ .entryPath('/auth/mixi')
+ .callbackPath('/auth/mixi/callback')
+
+ .authQueryParam('scope', function () {
+ return this._scope && this.scope();
+ })
+ .authQueryParam('response_type', function () {
+ return 'code';
+ })
+ .authQueryParam('display', function () {
+ return this._display && this.display();
+ })
+
+ .accessTokenParam('grant_type', function () {
+ return 'authorization_code';
+ })
+
+ .authCallbackDidErr( function (req) {
+ var parsedUrl = url.parse(req.url, true);
+ return parsedUrl.query && !!parsedUrl.query.error;
+ })
+ .handleAuthCallbackError( function (req, res) {
+ var parsedUrl = url.parse(req.url, true)
+ , errorDesc = parsedUrl.query.error_description;
+ if (res.render) {
+ res.render(__dirname + '/../views/auth-fail.jade', {
+ errorDescription: errorDesc
+ });
+ } else {
+ // TODO Replace this with a nice fallback
+ throw new Error("You must configure handleAuthCallbackError if you are not using express");
+ }
+ })
+
+ .fetchOAuthUser( function (accessToken) {
+ var p = this.Promise();
+ this.oauth.setAccessTokenName('oauth_token');
+ this.oauth.get(this.apiHost() + '/people/@me/@self', accessToken, function (err, data) {
+ if (err){
+ return p.fail(err);
+ }
+ var oauthUser = JSON.parse(data);
+ p.fulfill(oauthUser);
+ })
+ return p;
+ })
+ .convertErr( function (data) {
+ return new Error(JSON.parse(data.data).error.message);
+ });
+
+mixi.mobile = function (isMobile) {
+ if (isMobile) {
+ this.authPath('https://m.mixi.jp/connect_authorize.pl');
+ }
+ return this;
+};
View
BIN  media/mixi.ico
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.