Tags: , | Categories: asp.net mvc, rpx Posted by pieterg on 5/23/2010 4:26 AM | Comments (2)

The most annoying part of getting to a site is the bit where you have to register. It’s annoying having to complete a 50 page essay just to become part of the community. Since now, there have been numerous attempts to provide a single sign on facility and the only one worth exploring for me was RPX Now.

Let’s take a look at Stackoverflow and how Jeff Atwood and his team have just nailed the registration process.

image

Clicking on the Log In button will take you to a page that will ask you which provider you wish to sign in with. In my case, let’s use MyOpenID.

image

This will take you to myopenid.com and ask you to verify yourself and WHAM! You can associate your id with Stackoverflow and registration is complete. How did Jeff and his team manage this? I don’t know but it’s magic!

The one way to implement this is to use RPXNow and grab the RPXLib.

First up is to understand the process of RPX and how it will interact with your site. To break it down into simple bits.

1. User clicks on your log in link.
2. User is asked to choose a provider, be it twitter, google or openid.
3. User enters their credentials and gets passed into a void
4. Moments later the user is passed back to your page with a token. You can utilize this token to get details about the user.

1. User Clicks on your log in link

After following the simple directions on RPX Now, you should have a bunch of javascript and a link that was given to you.

<script type="text/javascript">
	var rpxJsHost = (("https:" == document.location.protocol) ? "https://" : "http://static.");
	document.write(unescape("%3Cscript src='" + rpxJsHost +
"rpxnow.com/js/lib/rpx.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
	RPXNOW.overlay = true;
	RPXNOW.language_preference = 'en';
</script>

<a class="rpxnow" onclick="return false;" href="https://mvcwebshop.rpxnow.com/openid/v2/signin?token_url=''>Sign In</a>

4. Moments later the user is passed back to your page with a token. You can utilize this token to get details about the user.

The user is passed back to your control and you are given a token to query the rpx service with.

/// <summary>
/// Sign In
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
[HttpPost]
public ActionResult SignIn(string token)
{
	return View();
}

Remember, to include the token as part of the parameters of the Action. Also, note the use of the attribute HttpPost. This tells asp.net mvc that this action will only respond to Http Posts.

Using this token and RPXLib, we can very easily query the service to get the user details, like so :)

/// <summary>
/// Sign in the user 
/// </summary>
/// <param name="username"></param>
/// <returns></returns>
public bool SignIn(string token)
{
	RPXLib.RPXService service = new RPXLib.RPXService(new RPXLib.RPXApiSettings("http://rpxnow.com/api/v2/auth_info", "youruniqueAPIKey"));
	try
	{
		RPXLib.Data.RPXAuthenticationDetails userDetails = service.GetUserData(token);
		return true;
	}
	catch (RPXLib.Exceptions.RPXAuthenticationErrorException ex)
	{
	}
	return false;
}

Remember that when setting up RPXNow, you can point it to your local development server (http://localhost:1234/SignIn/).

Have fun with it

Comments

pingback
topsy.com on 4/15/2010 10:46 PM Pingback from topsy.com

Twitter Trackbacks for
        
        ASP.NET MVC 2.0 and RPX Now
        [pieterg.com]
        on Topsy.com
pingback
60.jordanbrandallamerican.com on 4/20/2010 3:16 AM Pingback from 60.jordanbrandallamerican.com

1985 - 1983 @ Volkswagen Touareg Parts Slotted Brakes, Mercedes Benz Ml320 Discount Luxury Suv Volkswagen Touareg - 60.jordanbrandallamerican.com

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading