1
//-----------------------------------------------------------------------
2 // <copyright file="PapeUtilities.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth
.OpenId
.Extensions
.ProviderAuthenticationPolicy
{
9 using System
.Collections
.Generic
;
10 using System
.Globalization
;
13 using DotNetOpenAuth
.Messaging
;
16 /// Utility methods for use by the PAPE extension.
18 internal static class PapeUtilities
{
20 /// Looks at the incoming fields and figures out what the aliases and name spaces for auth level types are.
22 /// <param name="fields">The incoming message data in which to discover TypeURIs and aliases.</param>
23 /// <returns>The <see cref="AliasManager"/> initialized with the given data.</returns>
24 internal static AliasManager
FindIncomingAliases(IDictionary
<string, string> fields
) {
25 AliasManager aliasManager
= new AliasManager();
27 foreach (var pair
in fields
) {
28 if (!pair
.Key
.StartsWith(Constants
.AuthLevelNamespaceDeclarationPrefix
, StringComparison
.Ordinal
)) {
32 string alias = pair
.Key
.Substring(Constants
.AuthLevelNamespaceDeclarationPrefix
.Length
);
33 aliasManager
.SetAlias(alias, pair
.Value
);
36 aliasManager
.SetPreferredAliasesWhereNotSet(Constants
.AssuranceLevels
.PreferredTypeUriToAliasMap
);
42 /// Concatenates a sequence of strings using a space as a separator.
44 /// <param name="values">The elements to concatenate together..</param>
45 /// <returns>The concatenated string of elements.</returns>
46 /// <exception cref="FormatException">Thrown if any element in the sequence includes a space.</exception>
47 internal static string ConcatenateListOfElements(IEnumerable
<string> values
) {
48 ErrorUtilities
.VerifyArgumentNotNull(values
, "values");
50 StringBuilder valuesList
= new StringBuilder();
51 foreach (string value in values
.Distinct()) {
52 if (value.Contains(" ")) {
53 throw new FormatException(string.Format(CultureInfo
.CurrentCulture
, OpenIdStrings
.InvalidUri
, value));
55 valuesList
.Append(value);
56 valuesList
.Append(" ");
58 if (valuesList
.Length
> 0) {
59 valuesList
.Length
-= 1; // remove trailing space
61 return valuesList
.ToString();