.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification