Skip to content

Commit

Permalink
+ OAuth2AuthorizationRequestHeaderBearerAuthenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
prabirshrestha committed Jun 4, 2011
1 parent 34758a4 commit 81fe26c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/FluentHttp.Tests/FluentAuthenticators/OAuth2Authenticator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

// #define FLUENTHTTP_OAuth2UriQueryParameterBearerAuthenticator

namespace FluentHttp.Authenticators
{
using System;
Expand Down Expand Up @@ -40,6 +41,29 @@ public string BearerToken
}
}

class OAuth2AuthorizationRequestHeaderBearerAuthenticator : OAuth2BearerAuthenticator
{
/// <summary>
/// Initializes a new instance of the <see cref="OAuth2AuthorizationRequestHeaderBearerAuthenticator"/> class.
/// </summary>
/// <param name="bearerToken">The oauth 2 bearer_token.</param>
public OAuth2AuthorizationRequestHeaderBearerAuthenticator(string bearerToken)
: base(bearerToken)
{
}

/// <summary>
/// Authenticate the fluent http request using OAuth2 authorization header bearer_token.
/// </summary>
/// <param name="fluentHttpRequest">The fluent http request.</param>
public override void Authenticate(FluentHttpRequest fluentHttpRequest)
{
fluentHttpRequest.Headers(h => h.Add("Authorization", string.Concat("Bearer ", BearerToken)));
}
}

#if FLUENTHTTP_OAuth2UriQueryParameterBearerAuthenticator

class OAuth2UriQueryParameterBearerAuthenticator : OAuth2BearerAuthenticator
{
/// <summary>
Expand All @@ -60,4 +84,5 @@ public override void Authenticate(FluentHttpRequest fluentHttpRequest)
fluentHttpRequest.QueryStrings(qs => qs.Add("bearer_token", BearerToken));
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;TPL</DefineConstants>
<DefineConstants>TRACE;DEBUG;TPL;FLUENTHTTP_OAuth2UriQueryParameterBearerAuthenticator</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand All @@ -29,7 +29,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;TPL</DefineConstants>
<DefineConstants>TRACE;TPL;FLUENTHTTP_OAuth2UriQueryParameterBearerAuthenticator</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand Down

0 comments on commit 81fe26c

Please sign in to comment.