2013-07-02 91 views

回答

0

你需要什麼叫做屬性交換。這是OpenID的一項功能,允許從提供商交換用戶註冊數據(例如姓名,電子郵件等)。注意:受支持的屬性交換值列表不同於一個提供者。

假設你已經配置並運行OpenID的Spring Security,啓用屬性交換非常簡單。

<!--in your spring config --> 
<openid-login ....> 
    <!-- here is sample config for getting email --> 
    <attribute-exchange> 
    <openid-attribute 
     name="email" 
     type="http://schema.openid.net/contact/email" 
     required="true" 
    /> 
    </attribute-exchange> 
</openid-login> 

spring會將屬性數據保存到OpenIDAuthenticationToken。然後在你的* UserDetailsS​​ervice

public UserDetails loadUserDetails(OpenIDAuthenticationToken token) { 
    ... 
    List<OpenIDAttribute> attributes = token.getAttributes(); 
    user.setEmail(getAttribute("email", attributes)); 
    .. 
} 

private String getAttribute(String attrName, List<OpenIDAttribute> attrs) { 
    //do work to parse for email attribute 
} 
+0

我知道這一點。但是如果我使用,每當一個用戶要求登錄時,提供者總是要求用戶訪問信息。我只想第一次獲取信息 - 用戶登錄我的網站。 – user2524179

+0

請更新您的問題以反映您想要的內容!你問如何獲取用戶詳細信息 - 現在你說你已經知道這一點。 – ikumen

相關問題