询问如何在回调后获取用户个人资料

时间:2017-10-03 08:00:09

标签: angularjs node.js ajax ibm-cloud single-sign-on

我的Web应用程序正在使用IBM Bluemix的单点登录(SSO)服务。这是我的SSO服务的凭据信息:

    {
   "SingleSignOn": [
     {
       "credentials": {
         "secret": "MYSECRET",
         "tokenEndpointUrl": "https://adminwebsso-jjjfvxi6wy-cq17.iam.ibmcloud.com/idaas/oidc/endpoint/default/token",
         "authorizationEndpointUrl": "https://adminwebsso-jjjfvxi6wy-cq17.iam.ibmcloud.com/idaas/oidc/endpoint/default/authorize",
         "issuerIdentifier": "adminwebsso-jjjfvxi6wy-cq17.iam.ibmcloud.com",
         "clientId": "MYCLIENTID",
         "serverSupportedScope": [
           "openid"
         ]
       },
       "syslog_drain_url": null,
       "volume_mounts": [],
       "label": "SingleSignOn",
       "provider": null,
       "plan": "professional",
       "name": "VA-Admin-Console-R1-SSO",
       "tags": [
         "security",
         "ibm_created",
         "ibm_dedicated_public"
       ]
     }
   ]
 }

从我的应用程序中,我重定向到IBM的登录页面,如URL:

https://adminwebsso-jjjfvxi6wy-cq17.iam.ibmcloud.com/idaas/oidc/endpoint/default/authorize?response_type=code&client_id=MYCLIENTID&redirect_uri=http://localhost/callback≻ope=openid%20openid

登录成功后,IBM重定向到我的Web应用程序,我可以获得参数" code"来自回调网址(http://localhost/callback?scope=openid&code=bngM6aV5cYHAvhv7wLAM5QSWFDARn7)。

从那里,我使用"代码"获取用户个人资料。我尝试使用AJAX获取用户个人资料:

var settings = {
   "async": true,
   "crossDomain": true,
   "url": "https://idaas.ng.bluemix.net/sps/oauth20sp/oauth20/token",
   "method": "POST",
   "headers": {
     "content-type": "application/x-www-form-urlencoded",
     "authorization": "Basic RXhhbXBsZV9BcHBJRDpWUFlndEdXRlRvYVpZSUNTRzhJeVZFV000bUZicGpsU2t4RlRRbzlySkRGZDdzckc=",
     "cache-control": "no-cache"
   },
   "data": {
     "client_secret": "MYSECRET",
     "grant_type": "authorization_code",
     "redirect_uri": "http://localhost/callback",
     "code": "bngM6aV5cYHAvhv7wLAM5QSWFDARn7",
     "client_id": "MYCLIENTID"
   }
 }

 $.ajax(settings).done(function (response) {
   console.log(response);
 });

从上面的ajax帖子中,我尝试使用"代码"来自回调,但我收到了一条错误消息:

  

500错误:无法建立后侧连接

我被困在这里并且不知道如何从SSO获取用户资料。

1 个答案:

答案 0 :(得分:0)

在SSO服务中有一些内置宏可用于获取用户名,有关详细信息,请参阅。

https://console.bluemix.net/docs/services/SingleSignOn/customizing_pages.html#customizing_pages

@ USERNAME @经过身份验证的用户的用户ID。