My favorites | Sign in
Project Logo
                
Search
for
Updated Apr 11, 2007 by Johnny.Bufu
Labels: Featured
AttributeExchangeHowTo  
How to transfer attributes using the Attribute Exchange extension.

Attribute Exchange HowTo

Relying Party sends a FetchRequest

FetchRequest fetch = FetchRequest.createFetchRequest();

fetch.addAttribute("FirstName", "http://schema.openid.net/namePerson/first", true);
fetch.addAttribute("LastName", "http://schema.openid.net/namePerson/last", true);
fetch.addAttribute("Email", "http://schema.openid.net/contact/email", true);

// wants up to three email addresses
fetch.setCount("Email", 3);

AuthRequest req = _consumerManager.authenticate(discovered, return_to);
req.addExtension(fetch);

OpenID Provider receives a FetchRequest

if (authReq.hasExtension(AxMessage.OPENID_NS_AX))
{
    MessageExtension ext = authReq.getExtension(AxMessage.OPENID_NS_AX)

    if (ext instanceof FetchRequest)
    {
        FetchRequest fetchReq = (FetchRequest) ext;
        Map required = fetchReq.getAttributes(true);
        Map optional = fetchReq.getAttributes(false);
        // prompt the user
    }
    else if (ext instanceof StoreRequest)
    {
        ...
    }
}

OpenID Provider sends a FetchResponse

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

    FetchResponse fetchResp = FetchResponse.createFetchResponse(fetchReq, userData);

    // (alternatively) manually add attribute values
    fetchResp.addAttribute("email", "http://schema.openid.net/contact/email", "user@example.com");

    authSuccess.addExtension(fetchResp);

Relying Party receives a FetchResponse

if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX))
{
    MessageExtension ext = authSuccess.getExtension(AxMessage.OPENID_NS_AX);

    if (ext instanceof FetchResponse)
    {
        FetchResponse fetchResp = (FetchResponse) ext;
        
        String firstName = fetcResp.getAttributeValue("FirstName");
        String lastName = fetchResp.getAttributeValue("LastName");
        
        // can have multiple values
        List emails = fetchResp.getAttributeValues("Email");
    }
    else if (ext instanceof StoreResponse)
    {
        ...
    }
}

Comment by bobysu, Oct 21, 2007

i using the code,but i didn't get value of email from www.myopenid.com.i don't know where is something wrong. I used the OPENID_NS_AX belowed. AxMessage?.OPENID_NS_AX = "http://openid.net/srv/ax/1.0-draft7"

Comment by zhoushuqun, Jan 03, 2008

Dear bobysu, use SRegHowTo instead for www.myopenid.com.

Comment by dnagoda, Feb 29, 2008

As of mid-December 2007, myopenid.com should handle attribute exchange as the example shows above.

Comment by thewebsemantic, Jun 09, 2008

No, myopenid doesn't seem to be working with FetchRequest?, however, it's working fine with SRegHowTo.

Comment by ricardo.mamani, Dec 11, 2008

Hello!

I cant get the value of email, fullname or others from myopenid using the posted code above (FetchRequest?). But using SRegRequest it works fine. Someone got attributes using FetchRequest? from openId or others openID providers? how?

Regards Ricardo

Comment by teges_sttt@yahoo.com, Apr 06, 2009

i cant rinning this example, how i get authReq from "OpenID Provider receives a FetchRequest?" anyone can help me.??? :D


Sign in to add a comment
Hosted by Google Code