2014-07-01 169 views
0

我試圖通過遵循http://openid.net/specs/openid-connect-core-1_0.html來實現OpenID-Connect。 我被困在第3.1.2.1節 它表示客戶端必須通過GET或POST發送認證請求。 我試過在節點中。NodeJS OpenID Connect身份驗證請求

這裏是我的index.js(客戶端:依賴方)

var express = require('express'); 
var router = express.Router(); 
var querystring = require('querystring'); 
var http = require('http'); 

var id_token = { 
    iss : true, 
    sub : true, 
    aud : true, 
    exp : true, 
    iat : true, 
    auth_time : false, 
    nonce : false, 
    acr : false, 
    amr : false, 
    azp : false 
}; 

var auth_request = { 
    scope : true, 
    response_type : true, 
    client_id : true, 
    redirect_uri : true, 
    state : true, 
    response_mode : false, 
    nonce : false, 
    display : false, 
    prompt : false, 
    max_age : false, 
    ui_locales : false, 
    id_token_hint : false, 
    login_hint : false, 
    acr_values : false 
}; 

/* GET home page. */ 
router.get('/', function(req, res) { 
    res.render('index', { title: 'Express' }); 
}); 

router.post('/', function(req, res) { 
    var formcontent = req.body; 
    if (formcontent.hasOwnProperty("oauth-request")){ 
     var oauthrequest = querystring.stringify(auth_request); 
     var options = { 
      host: 'localhost', 
      port: 3000, 
      path: '/users', 
      method: 'POST', 
      headers: { 
       'Content-Type': 'application/x-www-form-urlencoded', 
       'Content-Length': oauthrequest.length 
      } 
     }; 

     var req = http.request(options, function(response){ 
      response.setEncoding('utf8'); 
      var str = '' 
      response.on('data', function (chunk) { 
       str += chunk; 
      }); 

      response.on('end', function() { 
       console.log(str); 

      }); 
     }); 
     req.write(oauthrequest); 
     req.end(); 
    } 
}); 

module.exports = router; 

這裏是我的用戶代碼:(身份驗證服務器)

var express = require('express'); 
var router = express.Router(); 

/* GET users listing. */ 
router.get('/', function(req, res) { 
    res.send('respond with a resource'); 
}); 
router.post('/', function(req, res) { 
    //console.log(req.body);  
    res.writeHead(200, {"Content-Type": "text/html"}); 
    res.write( 
     "<!DOCTYPE html>" + 
     "<html lang='en' dir='ltr'>" + 
      "<head>" + 
       "<meta charset='utf-8'>" + 
       "<title>Hola Mundo</title>" + 
      "</head>" + 
      "<body>" + 
       "<script type='text/javascript'>alert('Hello World')</script>" + 
      "</body>" + 
      "</html>"); 
    res.end(); 
    //res.send(req.body); 
}); 

module.exports = router; 

正如在3.1節中提到。 2.1認證請求的範圍屬性可以彈出,所以我認爲認證應該能夠打開一個彈出窗口詢問用戶的登錄。但是我無法打開身份驗證服務器端的彈出窗口。 有人可以通過打開彈出窗口來請求服務器端的用戶登錄或檢查用戶是否已登錄,從而幫助我獲得代碼?

回答

1

它出現很多缺失部分:令牌端點等您可能想看看passport

看看任何的實現(在提供商)(這一個特別是實現OIDC:https://github.com/auth0/passport-auth0,但可能有其他)。

(authz)服務器端可以用oauthorize toolkit實現。

+0

感謝您的聯繫。我知道我現在還沒有完成整個實施。但如果你去鏈接我分享。我試圖用代碼實現3.1.1。我對鏈接3.1.1中的前4個步驟感到困惑。 [鏈接](http://openid.net/specs/openid-connect-core-1_0.html) – skjindal93

+0

請幫我這個。 – skjindal93