-
Notifications
You must be signed in to change notification settings - Fork 58
SRegHowTo
johnny.bufu edited this page Jun 4, 2015
·
1 revision
The usage pattern exemplified below is almost identical to the usage of Attribute Exchange.
Attribute Exchange can transfer any type of attributes. For more information see the OpenID Attribute Exchange 1.0 specification and OpenID Attribute Types.
SRegRequest sregReq = SRegRequest.createFetchRequest();
sregReq.addAttribute("fullname", true);
sregReq.addAttribute("nickname", true);
sregReq.addAttribute("email", true);
AuthRequest req = _consumerManager.authenticate(discovered, return_to);
req.addExtension(sregReq);
if (authReq.hasExtension(SRegMessage.OPENID_NS_SREG))
{
MessageExtension ext = authReq.getExtension(SRegMessage.OPENID_NS_SREG)
if (ext instanceof SRegRequest)
{
SRegRequest sregReq = (SRegRequest) ext;
List required = sregReq.getAttributes(true);
List optional = sregReq.getAttributes(false);
// prompt the user
}
}
// data released by the user
Map userData = new HashMap();
//userData.put("email", "[email protected]");
SRegResponse sregResp = SRegResponse.createSRegResponse(sregReq, userData);
// (alternatively) manually add attribute values
sregResp.addAttribute("email", "[email protected]");
authSuccess.addExtension(sregResp);
serverManager.sign(authSuccess);
if (authSuccess.hasExtension(SRegMessage.OPENID_NS_SREG))
{
MessageExtension ext = authSuccess.getExtension(SRegMessage.OPENID_NS_SREG);
if (ext instanceof SRegResponse)
{
SRegResponse sregResp = (SRegResponse) ext;
String fullName = sregResp.getAttributeValue("fullname");
String nickName = sregResp.getAttributeValue("nickname");
String email = sregResp.getAttributeValues("email");
}
}