summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-04-22 08:00:42 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2012-04-22 08:00:42 -0700
commit94d1c68291865dc4557c599ce19cbec3c10541ff (patch)
treef4037266b384f92435b8132a80ea917befa92c32 /src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
parent1b6d8c2a40a019b43b252102353170380872da45 (diff)
downloadDotNetOpenAuth-94d1c68291865dc4557c599ce19cbec3c10541ff.zip
DotNetOpenAuth-94d1c68291865dc4557c599ce19cbec3c10541ff.tar.gz
DotNetOpenAuth-94d1c68291865dc4557c599ce19cbec3c10541ff.tar.bz2
Fixes access denial errors from OAuth 2 resource servers so they include the required parameters in their WWW-Authenticate headers.
Fixes #124
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs')
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs45
1 files changed, 21 insertions, 24 deletions
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
index 661d102..4c46f75 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
@@ -55,29 +55,6 @@ namespace DotNetOpenAuth.OAuth2 {
@"!#$%&'()*+-./:<=>?@[]^_`{|}~\,;";
/// <summary>
- /// Determines whether one given scope is a subset of another scope.
- /// </summary>
- /// <param name="requestedScope">The requested scope, which may be a subset of <paramref name="grantedScope"/>.</param>
- /// <param name="grantedScope">The granted scope, the suspected superset.</param>
- /// <returns>
- /// <c>true</c> if all the elements that appear in <paramref name="requestedScope"/> also appear in <paramref name="grantedScope"/>;
- /// <c>false</c> otherwise.
- /// </returns>
- public static bool IsScopeSubset(string requestedScope, string grantedScope) {
- if (string.IsNullOrEmpty(requestedScope)) {
- return true;
- }
-
- if (string.IsNullOrEmpty(grantedScope)) {
- return false;
- }
-
- var requestedScopes = new HashSet<string>(requestedScope.Split(scopeDelimiter, StringSplitOptions.RemoveEmptyEntries));
- var grantedScopes = new HashSet<string>(grantedScope.Split(scopeDelimiter, StringSplitOptions.RemoveEmptyEntries));
- return requestedScopes.IsSubsetOf(grantedScopes);
- }
-
- /// <summary>
/// Identifies individual scope elements
/// </summary>
/// <param name="scope">The space-delimited list of scopes.</param>
@@ -97,13 +74,33 @@ namespace DotNetOpenAuth.OAuth2 {
/// </summary>
/// <param name="scopes">The scopes to serialize.</param>
/// <returns>A space-delimited list.</returns>
- public static string JoinScopes(HashSet<string> scopes) {
+ public static string JoinScopes(ISet<string> scopes) {
Requires.NotNull(scopes, "scopes");
VerifyValidScopeTokens(scopes);
return string.Join(" ", scopes.ToArray());
}
/// <summary>
+ /// Parses a space-delimited list of scopes into a set.
+ /// </summary>
+ /// <param name="scopes">The space-delimited string.</param>
+ /// <returns>A set.</returns>
+ internal static ISet<string> ParseScopeSet(string scopes) {
+ Requires.NotNull(scopes, "scopes");
+ return ParseScopeSet(scopes.Split(scopeDelimiter, StringSplitOptions.RemoveEmptyEntries));
+ }
+
+ /// <summary>
+ /// Creates a set out of an array of strings.
+ /// </summary>
+ /// <param name="scopes">The array of strings.</param>
+ /// <returns>A set.</returns>
+ internal static ISet<string> ParseScopeSet(string[] scopes) {
+ Requires.NotNull(scopes, "scopes");
+ return new HashSet<string>(scopes, StringComparer.Ordinal);
+ }
+
+ /// <summary>
/// Verifies that a sequence of scope tokens are all valid.
/// </summary>
/// <param name="scopes">The scopes.</param>