プロトタイプ作成着手
とりあえず色々確認しつつ。要件としては
- facebook に oauth でログイン
できるのが milestone かな。node のバージョンは v0.4.12
$ node -v v0.4.12 $
express 導入。
$ npm install -g express /home/hoge/.nvm/v0.4.12/bin/express -> /home/hoge/.nvm/v0.4.12/lib/node_modules/express/bin/express mkdirp@0.0.7 /home/hoge/.nvm/v0.4.12/lib/node_modules/express/node_modules/mkdirp qs@0.3.2 /home/hoge/.nvm/v0.4.12/lib/node_modules/express/node_modules/qs mime@1.2.4 /home/hoge/.nvm/v0.4.12/lib/node_modules/express/node_modules/mime connect@1.7.3 /home/hoge/.nvm/v0.4.12/lib/node_modules/express/node_modules/connect express@2.5.0 /home/hoge/.nvm/v0.4.12/lib/node_modules/express $
express でプロジェクトが作れれば良いので connect-auth はプロジェクトの中でナニ。導入完了したのでプロジェクト作成。
express hoge create : hoge create : hoge/package.json create : hoge/app.js create : hoge/public create : hoge/routes create : hoge/routes/index.js create : hoge/views create : hoge/views/layout.jade create : hoge/views/index.jade create : hoge/public/javascripts create : hoge/public/images create : hoge/public/stylesheets create : hoge/public/stylesheets/style.css dont forget to install dependencies: $ cd hoge && npm install $
あと connect-auth のバージョン確認。
$ npm search connect-auth NAME DESCRIPTION AUTHOR KEYWORDS connect-auth Middleware for Connect (node.js) for handling your authentication needs. =ciaranj $
うう、バージョン分からんではないか。info とか show とかのあたりなの? と言いつつ npm info してみたら出力が丁寧で吃驚。
$ npm info connect-auth { name: 'connect-auth', description: 'Middleware for Connect (node.js) for handling your authentication needs.', 'dist-tags': { latest: '0.4.1' }, versions: [ '0.0.1', '0.0.2', '0.0.3', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.3.0', '0.3.1', '0.3.2', '0.4.0', '0.4.1' ], maintainers: 'ciaranj <ciaranj@gmail.com>', author: 'Ciaran Jessup <ciaranj@gmail.com>', time: { '0.0.1': '2011-03-16T16:01:31.368Z', '0.0.2': '2011-03-16T16:01:31.368Z', '0.0.3': '2011-03-16T16:01:31.368Z', '0.1.0': '2011-03-16T16:01:31.368Z', '0.1.1': '2011-03-16T16:01:31.368Z', '0.1.2': '2011-03-16T16:01:31.368Z', '0.1.3': '2011-03-16T16:01:31.368Z', '0.2.0': '2011-03-16T16:01:31.368Z', '0.2.1': '2011-03-16T16:01:31.368Z', '0.2.2': '2011-03-16T16:01:31.368Z', '0.2.3': '2011-06-22T23:03:18.069Z', '0.3.0': '2011-07-17T21:38:25.227Z', '0.3.1': '2011-08-06T20:38:21.140Z', '0.3.2': '2011-08-15T22:48:06.970Z', '0.4.0': '2011-08-21T21:44:12.221Z', '0.4.1': '2011-09-04T22:34:17.661Z' }, repository: { type: 'git', url: 'git://github.com/ciaranj/connect-auth.git' }, version: '0.4.1', engines: { node: '>=0.4.0' }, main: 'lib/index.js', directories: { lib: './lib' }, devDependencies: { expresso: '0.7.7' }, dependencies: { connect: '>= 1.4.3', oauth: '>= 0.9.4', openid: '0.3.1' }, dist: { shasum: '2497f911afa8eb41850efb52019c97c13e365b21', tarball: 'http://registry.npmjs.org/connect-auth/-/connect-auth-0.4.1.tgz' }, scripts: {} } $
ええと、上記によれば 0.4.1 で良いのかな。expresso も入れときたいんですが。0.7.7 以上ってことで良いのかな。info によれば 0.9.2 が最新らしいけど 0.7.7 にしとく。
ということで、package.json を以下に
{ "name": "hoge" , "version": "0.0.1" , "private": true , "dependencies": { "express": "2.5.0" , "jade": ">= 0.0.1" , "connect-auth": "0.4.1" , "expresso": "0.7.7" } }
で、npm install します。
$ npm install
ちょっと時間かかるかも。あ、済んでますね。
express@2.5.0 ./node_modules/express ├── mime@1.2.4 ├── mkdirp@0.0.7 ├── qs@0.3.2 └── connect@1.7.3 jade@0.17.0 ./node_modules/jade ├── mkdirp@0.1.0 └── commander@0.2.1 connect-auth@0.4.1 ./node_modules/connect-auth ├── openid@0.3.1 ├── oauth@0.9.5 └── connect@1.7.3 expresso@0.7.7 ./node_modules/expresso
あと、とりあえず以下な .gitignore を追加。
node_modules *~
で、git init して git status を見てみます。
$ git init Initialized empty Git repository in /home/hoge/Documents/nodejs/hoge/.git/ $ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # .gitignore # app.js # package.json # public/ # routes/ # views/ nothing added to commit but untracked files present (use "git add" to track) $
とりあえず commit します。
$ git add . $ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: .gitignore # new file: app.js # new file: package.json # new file: public/stylesheets/style.css # new file: routes/index.js # new file: views/index.jade # new file: views/layout.jade # $ git commit -m 'initial commit' [master (root-commit) 486fbc8] initial commit 7 files changed, 71 insertions(+), 0 deletions(-) create mode 100644 .gitignore create mode 100644 app.js create mode 100644 package.json create mode 100644 public/stylesheets/style.css create mode 100644 routes/index.js create mode 100644 views/index.jade create mode 100644 views/layout.jade $
ここまでが準備でここからが本番。てゆーか require の仕方が分からんぞorz
repl で確認
node_modules に入ってればそのまんま書けば良いはず。
$ node > var connect = require('connect-auth'); > connect { [Function] Bitbucket: [Getter], Janrain: [Getter], Github: [Getter], Yahoo: [Getter], Twitter: [Getter], Never: [Getter], Facebook: [Getter], Sina: [Getter], Anonymous: [Getter], Foursquare: [Getter], Google: [Getter], Google2: [Getter], Getglue: [Getter], Openid: [Getter], Digest: [Getter], Mac: [Getter], Http: [Getter], Basic: [Getter], Oauth: [Getter] } >
おそらく大丈夫なはず。とは言え、connect-auth の example とスリ合わせないと、なあたりが色々大変なのかどうか。
あら?
この後何するんだっけ。
- routing な記述
- createServer なナニに auth 云々をナニ?
- よく考えたらログインできてないのであれば強制的に req.authenticate すれば良いのかな
- これ、node な REPL で確認必要ですが
ちょっと今日は限界なので明日の朝練でも、ということで今日はクタバる方向orz