Browse files

add mixi.js and edit README.md

  • Loading branch information...
1 parent a8c7637 commit 209deefa23b9e86745a2b084dcbc39efb7d981b0 @ainoya ainoya committed Feb 26, 2012
Showing with 103 additions and 0 deletions.
  1. +26 −0 README.md
  2. +77 −0 lib/modules/mixi.js
View
26 README.md
@@ -40,6 +40,7 @@ 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"> mixi <td> <a href="https://github.com/dannyamey">mixi</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>
@@ -1682,6 +1683,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 CLIENT ID HERE')
+ .appSecret('YOUR TOKEN 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
77 lib/modules/mixi.js
@@ -0,0 +1,77 @@
+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();
+ console.log('fetchOAuthUser : '+ accessToken + ", " + this.apiHost()+ '/people/@me/@self');
+ this.oauth.setAccessTokenName('oauth_token');
+ this.oauth.get(this.apiHost() + '/people/@me/@self', accessToken, function (err, data) {
+ console.log('fetchOAuthUser2 : ');
+ if (err){
+ return p.fail(err);
+ }
+ console.log('fetchOAuthUser3');
+ var oauthUser = JSON.parse(data);
+ p.fulfill(oauthUser);
+ })
+ return p;
+ })
+ .convertErr( function (data) {
+ console.log('convertErr :'+ data.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;
+};

0 comments on commit 209deef

Please sign in to comment.