Passport Authentication
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngbeta' list.


Martin_Johnson
Hi,

I am trying to implement Passport authentication on a site that I am
developing using .Net beta 1. I am having problems in getting the Puid and
the profile. Can anyone share code snippets of implementing Passport and
getting the Puid and profile of the user.

Thanks and Regards,
Martin Johnson
Software Engineer
Satyam Computer Services Ltd - MCG

Reply to this message...
 
    
Steve Turley
It's been a while since I worked with this, but the code below should be
pretty close.
Create a config.web like this:
<configuration>
<security>
<authentication mode=3D"passport">
<passport redirecturl=3D"internal"/>
</authentication>
<authorization>
<deny users=3D"?"/>
</authorization>
</security>
</configuration>
The deny users part prohibits anyone from seeing your pages until
they're authenticated. The redirecturl is the place where users are sent
to sign in. "Internal" sends them to a built-in page; you can supply the
URL of your own page if you prefer. You can omit the authorization part
and handle the sign-in on your own, like classic Passport. The beauty of
doing it in config.web is that it automatically applies to the whole
site and you don't have to put authorization logic in every page.

The main aspx page structure should look like this:

<%@ Page Language=3D"C#" %>
<%@ Import Namespace=3D"System.Web.Security" %>

<html>
<head>
<title>Simple Passport Test</title>
</head>

<body>
<H2>Passport Simple Test</H2>
<%
try=20
{
if ( !(Context.User.Identity is PassportIdentity) )
{
Response.Write("Error: Passport authentication failed. Make sure
that the passport SDK (v1.4) is installed.");
    return;
}

// Expire the page to avoid the browser's cache
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Expires =3D 0;
Response.AppendHeader( "Cache-Control", "no-cache" );
Response.AppendHeader( "Pragma", "no-cache" );

string sThisPage =3D "http://"; +
Request.ServerVariables["SERVER_NAME"] +
Request.ServerVariables["SCRIPT_NAME"];
=20
PassportIdentity id =3D (PassportIdentity)Context.User.Identity;
=20
Response.Write("<p>" + id.LogoTag()); // beta1
Response.Write("<p/>\n");

// Removes passport cookies passed on query string after a user logs
in.
if ( id.GetFromNetworkServer )
{
Response.Redirect(sThisPage);
}

if (id.IsAuthenticated)
{
// id.Name returns the PUID
    Response.Write("<b>You have been authenticated as Passport
identity: " + id.Name + "</b><p/>\n");

if (id.HasProfile("core"))
{
    Response.Write("<b>Profile Objects</b><br/>\n");
    Response.Write("Birthdate: " + id["Birthdate"] + "<br>\n");
//alternate technique
    Response.Write("Birthdate: " + id.GetProfileObject("Birthdate")
+ "<br>\n");

// PUID can be built from IDHigh + IDLow
    Response.Output.Write("Member ID High: 0x{0:X8}<br>\n",
id.GetProfileObject("memberIDHigh"));
    Response.Output.Write("Member ID Low: 0x{0:X8}<br>\n",
id.GetProfileObject("memberIDLow"));
    }
else
{
    Response.Write("<br/>\n");
    Response.Write("<b>No Profile available</b><br/>\n");
}
}
else if (id.HasTicket) //stale ticket
{
Response.Write("Your ticket is stale. (" + id.TicketAge + "
seconds old) <a href=3D\"" + id.AuthUrl() + "\">refresh</a>\n");
}
else
{
Response.Write("Not authenticated, please sign in");
}
}=20
catch ( Exception e)=20
{
Response.Write( "Unhandled exception: " + e.Message );
}
%>

</body>
</html>

The site's "delete cookies" page simply needs to call
PassportIdentity.SignOut();

-----Original Message-----
From: Martin_Johnson [mailto:Click here to reveal e-mail address]
Sent: Sunday, May 06, 2001 9:16 PM
To: aspngbeta
Subject: [aspngbeta] Passport Authentication

Hi,

I am trying to implement Passport authentication on a site that I am
developing using .Net beta 1. I am having problems in getting the Puid
and
the profile. Can anyone share code snippets of implementing Passport and
getting the Puid and profile of the user.

Thanks and Regards,
Martin Johnson
Software Engineer
Satyam Computer Services Ltd - MCG

| [aspngbeta] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp =3D JOIN/QUIT

Reply to this message...
 
 
System.Runtime.Remoting.Contexts.Context
System.Web.HttpCacheability
System.Web.Security.PassportIdentity




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com