我試着寫一個skeleton app進行身份驗證使用Mozilla Persona使用thistutorial和passportdocumentation和登錄總是失敗 - 我不知道我在做什麼錯因爲我沒有看到護照上的日誌。這是我的front-end code,這是我的server code,我確實看到Persona彈出窗口,但從彈出窗口登錄時,req.isAuthenticated()
始終爲false。假面(BROWSERID)認證從來沒有成功地表達3.0(與護照BROWSERID)
下面是客戶端代碼片段:
<script type="text/coffeescript">
$ ->
$('#signin').click -> navigator.id.request()
$('#signout').click -> navigator.id.logout()
navigator.id.watch
onlogin: (assertion) ->
$.ajax
type: 'POST'
url: '/login'
data: assertion: assertion
success: (res, status, xhr) ->
console.log res
error: (res, status, xhr) -> alert "login failure" + res
onlogout: ->
console.log 'logout'
</script>
這是服務器代碼:
express = require 'express'
passport = require 'passport'
BrowserIDStrategy = require('passport-browserid').Strategy
app = express()
passport.serializeUser (user, done) ->
log 'serializing user #{user}'
done null, user.email
passport.deserializeUser (email, done) ->
log 'deserializing email #{email}'
done null, email: email
persona_audience = "http://#{config.server.host}:#{config.server.port}"
passport.use new BrowserIDStrategy audience: persona_audience,
(email, done) ->
log email
done null, email: email
app.get '/test', (req, res) ->
msg = if req.isAuthenticated() then "Congratulations! You've signed in as #{req.user.email}" else "Fail :(("
log msg
res.send msg
app.post '/login', passport.authenticate('browserid', {failureRedirect: '/test', successRedirect: '/test'})
app.get '/logout', (req, res) ->
req.logOut()
res.redirect '/'
app.configure ->
# app.use express.logger()
app.use express.cookieParser(config.server.session_secret)
app.use express.session()
app.use express.bodyParser()
app.use express.methodOverride()
app.use passport.initialize()
app.use passport.session()
app.use app.router
app.use express['static'](__dirname + '/public')
錯誤是什麼? – chovy
我總是碰到'log':('''在我的代碼中的行,即''req.isAuthenticated()'總是'false' – pathikrit
此外,它從不碰到'serializeUser'或'deserializeUser'方法 – pathikrit