Skip to content

Commit

Permalink
If using the default oauth token, we will use the request's host & po…
Browse files Browse the repository at this point in the history
…rt, rather than rely on the user to specify them for us.
  • Loading branch information
ayende committed Mar 22, 2013
1 parent eddc268 commit addaa36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Raven.Database/Config/InMemoryRavenConfiguration.cs
Expand Up @@ -254,6 +254,11 @@ private void SetVirtualDirectory()

}

public bool UseDefaultOAuthTokenServer
{
get { return Settings["Raven/OAuthTokenServer"] == null; }
}

private void SetupOAuth()
{
OAuthTokenServer = Settings["Raven/OAuthTokenServer"] ??
Expand Down
14 changes: 13 additions & 1 deletion Raven.Database/Server/Security/OAuth/OAuthRequestAuthorizer.cs
Expand Up @@ -109,7 +109,19 @@ void WriteAuthorizationChallenge(IHttpContext ctx, int statusCode, string error,
{
if (string.IsNullOrEmpty(Settings.OAuthTokenServer) == false)
{
ctx.Response.AddHeader("OAuth-Source", Settings.OAuthTokenServer);
if (Settings.UseDefaultOAuthTokenServer == false)
{
ctx.Response.AddHeader("OAuth-Source", Settings.OAuthTokenServer);
}
else
{
ctx.Response.AddHeader("OAuth-Source", new UriBuilder(Settings.OAuthTokenServer)
{
Host = ctx.Request.Url.Host,
Port = ctx.Request.Url.Port
}.Uri.ToString());

}
}
ctx.Response.StatusCode = statusCode;
ctx.Response.AddHeader("WWW-Authenticate", string.Format("Bearer realm=\"Raven\", error=\"{0}\",error_description=\"{1}\"", error, errorDescription));
Expand Down
2 changes: 2 additions & 0 deletions Raven.Tryouts/Program.cs
Expand Up @@ -15,6 +15,8 @@ class Program
{
static void Main(string[] args)
{
var uri = new Uri("ftp://localhost/");
Console.WriteLine(uri.Port);
}
}
}

0 comments on commit addaa36

Please sign in to comment.