summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-01-18 02:30:32 +0000
committerAndrew <andrewarnott@gmail.com>2008-01-18 02:30:32 +0000
commit61f57bbaf71e22c83dae7958bc3ca4fb983fdce7 (patch)
tree6a4c0e3768afe40b7f7bc1e10f51b115281c05aa
parentfd169ef57aa63a8768ac6f824ed7d244ffa2a97a (diff)
downloadDotNetOpenAuth-61f57bbaf71e22c83dae7958bc3ca4fb983fdce7.zip
DotNetOpenAuth-61f57bbaf71e22c83dae7958bc3ca4fb983fdce7.tar.gz
DotNetOpenAuth-61f57bbaf71e22c83dae7958bc3ca4fb983fdce7.tar.bz2
Swapping out 'magic strings' with constants defined in a central place.
git-svn-id: https://dotnetopenid.googlecode.com/svn/trunk@76 01efa1a6-402a-0410-b0ae-47b76eba00f0
-rw-r--r--source/Janrain.OpenId/Consumer/AuthRequest.cs14
-rw-r--r--source/Janrain.OpenId/Consumer/ConsumerResponse.cs2
-rw-r--r--source/Janrain.OpenId/Consumer/GenericConsumer.cs36
-rw-r--r--source/Janrain.OpenId/Consumer/OpenIdTextBox.cs28
-rw-r--r--source/Janrain.OpenId/Server/CheckIdRequest.cs16
-rw-r--r--source/Janrain.OpenId/Server/ProtocolException.cs2
-rw-r--r--source/Janrain.OpenId/Util.cs45
7 files changed, 94 insertions, 49 deletions
diff --git a/source/Janrain.OpenId/Consumer/AuthRequest.cs b/source/Janrain.OpenId/Consumer/AuthRequest.cs
index a75a231..bff853d 100644
--- a/source/Janrain.OpenId/Consumer/AuthRequest.cs
+++ b/source/Janrain.OpenId/Consumer/AuthRequest.cs
@@ -50,22 +50,22 @@ namespace Janrain.OpenId.Consumer
{
string modeStr = String.Empty;
if (mode == Mode.IMMEDIATE)
- modeStr = "checkid_immediate";
+ modeStr = QueryStringArgs.OpenIdModes.CheckIdImmediate;
else if (mode == Mode.SETUP)
- modeStr = "checkid_setup";
+ modeStr = QueryStringArgs.OpenIdModes.CheckIdSetup;
UriBuilder returnToBuilder = new UriBuilder(returnTo);
UriUtil.AppendQueryArgs(returnToBuilder, this.ReturnToArgs);
NameValueCollection qsArgs = new NameValueCollection();
- qsArgs.Add("openid.mode", modeStr);
- qsArgs.Add("openid.identity", this.endpoint.ServerId.AbsoluteUri); //TODO: breaks the Law of Demeter
- qsArgs.Add("openid.return_to", new Uri(returnToBuilder.ToString(), true).AbsoluteUri); //TODO: obsolete, problem?
- qsArgs.Add("openid.trust_root", trustRoot);
+ qsArgs.Add(QueryStringArgs.OpenIdMode, modeStr);
+ qsArgs.Add(QueryStringArgs.OpenIdIdentity, this.endpoint.ServerId.AbsoluteUri); //TODO: breaks the Law of Demeter
+ qsArgs.Add(QueryStringArgs.OpenIdReturnTo, returnToBuilder.ToString());
+ qsArgs.Add(QueryStringArgs.OpenIdTrustRoot, trustRoot);
if (this.assoc != null)
- qsArgs.Add("openid.assoc_handle", this.assoc.Handle); // !!!!
+ qsArgs.Add(QueryStringArgs.OpenIdAssocHandle, this.assoc.Handle); // !!!!
UriBuilder redir = new UriBuilder(this.endpoint.ServerUrl);
diff --git a/source/Janrain.OpenId/Consumer/ConsumerResponse.cs b/source/Janrain.OpenId/Consumer/ConsumerResponse.cs
index ffe110a..117363e 100644
--- a/source/Janrain.OpenId/Consumer/ConsumerResponse.cs
+++ b/source/Janrain.OpenId/Consumer/ConsumerResponse.cs
@@ -16,7 +16,7 @@ namespace Janrain.OpenId.Consumer
public Uri ReturnTo
{
- get { return new Uri((string)this.signed_args["openid.return_to"], true); }
+ get { return new Uri((string)this.signed_args[QueryStringArgs.OpenIdReturnTo], true); }
}
public ConsumerResponse(Uri identity_url, NameValueCollection query, string signed)
diff --git a/source/Janrain.OpenId/Consumer/GenericConsumer.cs b/source/Janrain.OpenId/Consumer/GenericConsumer.cs
index 80fe96f..4359fdf 100644
--- a/source/Janrain.OpenId/Consumer/GenericConsumer.cs
+++ b/source/Janrain.OpenId/Consumer/GenericConsumer.cs
@@ -44,7 +44,7 @@ namespace Janrain.OpenId.Consumer
public ConsumerResponse Complete(NameValueCollection query, string token)
{
- string mode = query["openid.mode"];
+ string mode = query[QueryStringArgs.OpenIdMode];
if (mode == null)
mode = "<no mode specified>";
@@ -61,24 +61,24 @@ namespace Janrain.OpenId.Consumer
server_url = (Uri)pieces[2];
}
- if (mode == "cancel")
+ if (mode == QueryStringArgs.OpenIdModes.Cancel)
throw new CancelException(identity_url);
-
- if (mode == "error")
+
+ if (mode == QueryStringArgs.OpenIdModes.Error)
{
- string error = query["openid.error"];
+ string error = query[QueryStringArgs.OpenIdError];
throw new FailureException(identity_url, error);
}
- if (mode == "id_res")
+ if (mode == QueryStringArgs.OpenIdModes.IdRes)
{
if (identity_url == null)
throw new FailureException(identity_url, "No session state found");
ConsumerResponse response = DoIdRes(query, identity_url, server_id, server_url);
- CheckNonce(response, query["nonce"]);
+ CheckNonce(response, query[QueryStringArgs.Nonce]);
return response;
}
@@ -105,7 +105,7 @@ namespace Janrain.OpenId.Consumer
{
NameValueCollection nvc = HttpUtility.ParseQueryString(response.ReturnTo.Query);
- string value = nvc["nonce"];
+ string value = nvc[QueryStringArgs.Nonce];
if (String.IsNullOrEmpty(value))
throw new FailureException(response.IdentityUrl,
"Nonce missing from return_to: " +
@@ -144,20 +144,20 @@ namespace Janrain.OpenId.Consumer
{
Converter<string, string> getRequired = delegate(string key)
{
- string val = query["openid." + key];
+ string val = query[key];
if (val == null)
throw new FailureException(consumer_id, "Missing required field: " + key);
return val;
};
- string user_setup_url = query["openid.user_setup_url"];
+ string user_setup_url = query[QueryStringArgs.OpenIdUserSetupUrl];
if (user_setup_url != null)
throw new SetupNeededException(consumer_id, new Uri(user_setup_url));
- string return_to = getRequired("return_to");
- string server_id2 = getRequired("identity");
- string assoc_handle = getRequired("assoc_handle");
+ string return_to = getRequired(QueryStringArgs.OpenIdReturnTo);
+ string server_id2 = getRequired(QueryStringArgs.OpenIdIdentity);
+ string assoc_handle = getRequired(QueryStringArgs.OpenIdAssocHandle);
if (server_id.AbsoluteUri != server_id.ToString())
throw new FailureException(consumer_id, "Server ID (delegate) mismatch");
@@ -171,7 +171,7 @@ namespace Janrain.OpenId.Consumer
if (!CheckAuth(query, server_url))
throw new FailureException(consumer_id, "check_authentication failed");
- return new ConsumerResponse(consumer_id, query, query["openid.signed"]);
+ return new ConsumerResponse(consumer_id, query, query[QueryStringArgs.OpenIdSigned]);
}
if (assoc.ExpiresIn <= 0)
@@ -180,8 +180,8 @@ namespace Janrain.OpenId.Consumer
}
// Check the signature
- string sig = getRequired("sig");
- string signed = getRequired("signed");
+ string sig = getRequired(QueryStringArgs.OpenIdSig);
+ string signed = getRequired(QueryStringArgs.OpenIdSigned);
string[] signed_array = signed.Split(',');
string v_sig = assoc.SignDict(signed_array, query, "openid.");
@@ -226,7 +226,7 @@ namespace Janrain.OpenId.Consumer
private NameValueCollection CreateCheckAuthRequest(NameValueCollection query)
{
- string signed = query["openid.signed"];
+ string signed = query[QueryStringArgs.OpenIdSigned];
if (signed == null)
// #XXX: oidutil.log('No signature present; checkAuth aborted')
@@ -249,7 +249,7 @@ namespace Janrain.OpenId.Consumer
if (key.StartsWith("openid.") && Array.IndexOf(signed_array, key.Substring(7)) > -1)
check_args.Add(key, query[key]);
- check_args["openid.mode"] = "check_authentication";
+ check_args[QueryStringArgs.OpenIdMode] = "check_authentication";
}
return check_args;
diff --git a/source/Janrain.OpenId/Consumer/OpenIdTextBox.cs b/source/Janrain.OpenId/Consumer/OpenIdTextBox.cs
index 291cdfb..26876e2 100644
--- a/source/Janrain.OpenId/Consumer/OpenIdTextBox.cs
+++ b/source/Janrain.OpenId/Consumer/OpenIdTextBox.cs
@@ -309,7 +309,7 @@ namespace NerdBank.OpenId.Consumer
try
{
- if (!Page.IsPostBack && Page.Request.QueryString["openid.mode"] != null)
+ if (!Page.IsPostBack && Page.Request.QueryString[QueryStringArgs.OpenIdMode] != null)
{
Janrain.OpenId.Consumer.Consumer consumer =
new Janrain.OpenId.Consumer.Consumer(new SystemHttpSessionState(Page.Session), MemoryStore.GetInstance());
@@ -357,7 +357,7 @@ namespace NerdBank.OpenId.Consumer
return_to.Query = string.Empty;
NameValueCollection return_to_params = new NameValueCollection(Page.Request.QueryString.Count);
foreach (string key in Page.Request.QueryString) {
- if (!key.StartsWith("openid.")) {
+ if (!key.StartsWith(QueryStringArgs.OpenIdPrefix)) {
return_to_params.Add(key, Page.Request.QueryString[key]);
}
}
@@ -401,31 +401,31 @@ namespace NerdBank.OpenId.Consumer
{
OpenIdProfileFields fields = new OpenIdProfileFields();
if (RequestNickname > ProfileRequest.NoRequest)
- fields.Nickname = queryString["openid.sreg.nickname"];
+ fields.Nickname = queryString[QueryStringArgs.OpenIdSregNickname];
if (RequestEmail > ProfileRequest.NoRequest)
- fields.Email = queryString["openid.sreg.email"];
+ fields.Email = queryString[QueryStringArgs.OpenIdSregEmail];
if (RequestFullName > ProfileRequest.NoRequest)
- fields.Fullname = queryString["openid.sreg.fullname"];
- if (RequestBirthdate > ProfileRequest.NoRequest && !string.IsNullOrEmpty(queryString["openid.sreg.dob"]))
+ fields.Fullname = queryString[QueryStringArgs.OpenIdSregFullname];
+ if (RequestBirthdate > ProfileRequest.NoRequest && !string.IsNullOrEmpty(queryString[QueryStringArgs.OpenIdSregDob]))
{
DateTime birthdate;
- DateTime.TryParse(queryString["openid.sreg.dob"], out birthdate);
+ DateTime.TryParse(queryString[QueryStringArgs.OpenIdSregDob], out birthdate);
fields.Birthdate = birthdate;
}
if (RequestGender > ProfileRequest.NoRequest)
- switch (queryString["openid.sreg.gender"])
+ switch (queryString[QueryStringArgs.OpenIdGender])
{
- case "M": fields.Gender = Gender.Male; break;
- case "F": fields.Gender = Gender.Female; break;
+ case QueryStringArgs.OpenIdGenders.Male: fields.Gender = Gender.Male; break;
+ case QueryStringArgs.OpenIdGenders.Female: fields.Gender = Gender.Female; break;
}
if (RequestPostalCode > ProfileRequest.NoRequest)
- fields.PostalCode = queryString["openid.sreg.postcode"];
+ fields.PostalCode = queryString[QueryStringArgs.OpenIdPostCode];
if (RequestCountry > ProfileRequest.NoRequest)
- fields.Country = queryString["openid.sreg.country"];
+ fields.Country = queryString[QueryStringArgs.OpenIdCountry];
if (RequestLanguage > ProfileRequest.NoRequest)
- fields.Language = queryString["openid.sreg.language"];
+ fields.Language = queryString[QueryStringArgs.OpenIdLanguage];
if (RequestTimeZone > ProfileRequest.NoRequest)
- fields.TimeZone = queryString["openid.sreg.timezone"];
+ fields.TimeZone = queryString[QueryStringArgs.OpenIdTimezone];
return fields;
}
diff --git a/source/Janrain.OpenId/Server/CheckIdRequest.cs b/source/Janrain.OpenId/Server/CheckIdRequest.cs
index 679bbb2..c3ffbc7 100644
--- a/source/Janrain.OpenId/Server/CheckIdRequest.cs
+++ b/source/Janrain.OpenId/Server/CheckIdRequest.cs
@@ -68,7 +68,7 @@ namespace Janrain.OpenId.Server
public CheckIdRequest(NameValueCollection query)
{
// handle the mandatory protocol fields
- string mode = query["openid.mode"];
+ string mode = query[QueryStringArgs.OpenIdMode];
if (mode == "checkid_immediate")
{
@@ -81,7 +81,7 @@ namespace Janrain.OpenId.Server
_mode = "checkid_setup";
}
- string identity = GetField(query, "identity");
+ string identity = GetField(query, QueryStringArgs.OpenIdIdentity);
try
{
_identity = new Uri(identity);
@@ -91,7 +91,7 @@ namespace Janrain.OpenId.Server
throw new ProtocolException(query, "openid.identity not a valid url: " + identity);
}
- string return_to = GetField(query, "return_to");
+ string return_to = GetField(query, QueryStringArgs.OpenIdReturnTo);
try
{
_return_to = new Uri(return_to);
@@ -122,20 +122,20 @@ namespace Janrain.OpenId.Server
// Handle the optional Simple Registration extension fields
- string policyUrl = GetSimpleRegistrationExtensionField(query, "policy_url");
+ string policyUrl = GetSimpleRegistrationExtensionField(query, QueryStringArgs.OpenIdSregPolicyUrl);
if (!String.IsNullOrEmpty(policyUrl))
{
_policyUrl = new Uri(policyUrl);
}
- string optionalFields = GetSimpleRegistrationExtensionField(query, "optional");
+ string optionalFields = GetSimpleRegistrationExtensionField(query, QueryStringArgs.OpenIdSregOptional);
if (!String.IsNullOrEmpty(optionalFields))
{
string[] splitOptionalFields = optionalFields.Split(',');
setSimpleRegistrationExtensionFields(splitOptionalFields, ProfileRequest.Request);
}
- string requiredFields = GetSimpleRegistrationExtensionField(query, "required");
+ string requiredFields = GetSimpleRegistrationExtensionField(query, QueryStringArgs.OpenIdSregRequired);
if (!String.IsNullOrEmpty(requiredFields))
{
string[] splitRrequiredFields = requiredFields.Split(',');
@@ -149,7 +149,7 @@ namespace Janrain.OpenId.Server
private string GetField(NameValueCollection query, string field)
{
- string value = query.Get("openid." + field);
+ string value = query.Get(field);
if (value == null)
throw new ProtocolException(query, "Missing required field " + field);
@@ -159,7 +159,7 @@ namespace Janrain.OpenId.Server
private string GetSimpleRegistrationExtensionField(NameValueCollection query, string field)
{
- string value = query.Get("openid.sreg." + field);
+ string value = query.Get(field);
return value;
}
diff --git a/source/Janrain.OpenId/Server/ProtocolException.cs b/source/Janrain.OpenId/Server/ProtocolException.cs
index 7b83bb7..4cf8a18 100644
--- a/source/Janrain.OpenId/Server/ProtocolException.cs
+++ b/source/Janrain.OpenId/Server/ProtocolException.cs
@@ -30,7 +30,7 @@ namespace Janrain.OpenId.Server
{
get
{
- return (_query["openid.return_to"] != null);
+ return (_query[QueryStringArgs.OpenIdReturnTo] != null);
}
}
diff --git a/source/Janrain.OpenId/Util.cs b/source/Janrain.OpenId/Util.cs
index 890a111..357a3bf 100644
--- a/source/Janrain.OpenId/Util.cs
+++ b/source/Janrain.OpenId/Util.cs
@@ -101,4 +101,49 @@ namespace Janrain.OpenId
#endregion
}
+ internal static class QueryStringArgs {
+ internal const string OpenIdPrefix = "openid.";
+
+ internal const string OpenIdReturnTo = "openid.return_to";
+ internal const string OpenIdMode = "openid.mode";
+ internal const string OpenIdError = "openid.error";
+ internal const string OpenIdIdentity = "openid.identity";
+ internal const string OpenIdAssocHandle = "openid.assoc_handle";
+ internal const string OpenIdSig = "openid.sig";
+ internal const string OpenIdSigned = "openid.signed";
+ internal const string OpenIdUserSetupUrl = "openid.user_setup_url";
+ internal const string OpenIdTrustRoot = "openid.trust_root";
+ internal const string Nonce = "nonce";
+
+ internal const string OpenIdSregPolicyUrl = "openid.sreg.policy_url";
+ internal const string OpenIdSregOptional = "openid.sreg.optional";
+ internal const string OpenIdSregRequired = "openid.sreg.required";
+ internal const string OpenIdSregNickname = "openid.sreg.nickname";
+ internal const string OpenIdSregEmail = "openid.sreg.email";
+ internal const string OpenIdSregFullname = "openid.sreg.fullname";
+ internal const string OpenIdSregDob = "openid.sreg.dob";
+ internal const string OpenIdGender = "openid.sreg.gender";
+ internal const string OpenIdPostCode = "openid.sreg.postcode";
+ internal const string OpenIdCountry = "openid.sreg.country";
+ internal const string OpenIdLanguage = "openid.sreg.language";
+ internal const string OpenIdTimezone = "openid.sreg.timezone";
+
+ internal static class OpenIdModes {
+ internal const string Cancel = "cancel";
+ internal const string Error = "error";
+ internal const string IdRes = "id_res";
+ internal const string CheckIdImmediate = "checkid_immediate";
+ internal const string CheckIdSetup = "checkid_setup";
+ }
+ internal static class OpenIdGenders {
+ internal const string Male = "M";
+ internal const string Female = "F";
+ }
+
+ /// <summary>
+ /// Used by ASP.NET on a login page to determine where a successful
+ /// login should be redirected to.
+ /// </summary>
+ internal const string ReturnUrl = "ReturnUrl";
+ }
}