Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Added flag for URL-escaping of scopes parameter #48

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Xamarin.Auth/OAuth2Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class OAuth2Authenticator : WebRedirectAuthenticator
string requestState;
bool reportedForgery = false;

bool encodeScope = true;

/// <summary>
/// Initializes a new <see cref="Xamarin.Auth.OAuth2Authenticator"/>
/// that authenticates using implicit granting (token).
Expand All @@ -63,7 +65,7 @@ public class OAuth2Authenticator : WebRedirectAuthenticator
/// Method used to fetch the username of an account
/// after it has been successfully authenticated.
/// </param>
public OAuth2Authenticator (string clientId, string scope, Uri authorizeUrl, Uri redirectUrl, GetUsernameAsyncFunc getUsernameAsync = null)
public OAuth2Authenticator (string clientId, string scope, Uri authorizeUrl, Uri redirectUrl, bool encodeScope = true, GetUsernameAsyncFunc getUsernameAsync = null)
: this (redirectUrl)
{
if (string.IsNullOrEmpty (clientId)) {
Expand All @@ -83,6 +85,8 @@ public OAuth2Authenticator (string clientId, string scope, Uri authorizeUrl, Uri
}
this.redirectUrl = redirectUrl;

this.encodeScope = encodeScope;

this.getUsernameAsync = getUsernameAsync;

this.accessTokenUrl = null;
Expand Down Expand Up @@ -114,7 +118,7 @@ public OAuth2Authenticator (string clientId, string scope, Uri authorizeUrl, Uri
/// Method used to fetch the username of an account
/// after it has been successfully authenticated.
/// </param>
public OAuth2Authenticator (string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null)
public OAuth2Authenticator (string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, bool encodeScope = true, GetUsernameAsyncFunc getUsernameAsync = null)
: this (redirectUrl, clientSecret, accessTokenUrl)
{
if (string.IsNullOrEmpty (clientId)) {
Expand All @@ -139,6 +143,8 @@ public OAuth2Authenticator (string clientId, string clientSecret, string scope,
}
this.redirectUrl = redirectUrl;

this.encodeScope = encodeScope;

if (accessTokenUrl == null) {
throw new ArgumentNullException ("accessTokenUrl");
}
Expand Down Expand Up @@ -186,7 +192,7 @@ public override Task<Uri> GetInitialUrlAsync ()
Uri.EscapeDataString (clientId),
Uri.EscapeDataString (redirectUrl.AbsoluteUri),
IsImplicit ? "token" : "code",
Uri.EscapeDataString (scope),
(encodeScope) ? Uri.EscapeDataString (scope) : scope,
Uri.EscapeDataString (requestState)));

var tcs = new TaskCompletionSource<Uri> ();
Expand Down