My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
SRegHowTo  
How to transfer attributes using the Simple Registration extension.
Featured
zh-Hans , en
Updated Feb 4, 2010 by Johnny.B...@gmail.com

Simple Registration HowTo

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.

Relying Party sends a SRegRequest

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);

OpenID Provider receives a SRegRequest

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
    }
}

OpenID Provider sends a SRegResponse

    // data released by the user
    Map userData = new HashMap();
    //userData.put("email", "user@example.com");

    SRegResponse sregResp = SRegResponse.createSRegResponse(sregReq, userData);

    // (alternatively) manually add attribute values
    sregResp.addAttribute("email", "user@example.com");

    authSuccess.addExtension(sregResp);

Relying Party receives a SRegResponse

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");
    }
}
Comment by sash...@gmail.com, Jun 13, 2009

String email = sregResp.getAttributeValues("email");

no such method in SRegResponse!

Comment by ashwanth...@gmail.com, Dec 1, 2009

its String email = sregResp.getAttributeValue("email");

Comment by BlessedGeek, Jan 22, 2010

Did exactly as above, and sent it to google server. Google server returned only the usual openid params, but did not return any email attribute.

Does google require their own type uris? http://code.google.com/apis/accounts/docs/OpenID.html.

Or, is it because the openid I supplied was associated with google blogger and google blogger does not associate its openids with the email id used to log into blogger?

Comment by daniel.o...@gmail.com, Aug 12, 2010

In which moment do i create de AuthSuccess? object ?

Comment by hao.nguy...@gmail.com, Oct 22, 2010

really badly documented

Comment by marcel.o...@gmail.com, Feb 4, 2011

Last line of code: String email = sregResp.getAttributeValues("email"); should be: String email = sregResp.getAttributeValue("email");


Sign in to add a comment
Powered by Google Project Hosting