File tree Expand file tree Collapse file tree 5 files changed +19
-5
lines changed
src/RestSharp/Authenticators Expand file tree Collapse file tree 5 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 2525 uses : actions/checkout@v3
2626 -
2727 name : Setup .NET
28- uses : actions/setup-dotnet@v2
28+ uses : actions/setup-dotnet@v3
2929 with :
3030 dotnet-version : ' 6.0'
3131 -
Original file line number Diff line number Diff line change 1515 uses : actions/checkout@v3
1616 -
1717 name : Setup .NET
18- uses : actions/setup-dotnet@v2
18+ uses : actions/setup-dotnet@v3
1919 with :
2020 dotnet-version : ' 6.0'
2121 -
Original file line number Diff line number Diff line change @@ -48,8 +48,8 @@ public class TwitterAuthenticator : AuthenticatorBase {
4848 }
4949
5050 protected override async ValueTask <Parameter > GetAuthenticationParameter (string accessToken ) {
51- var token = string .IsNullOrEmpty (Token ) ? await GetToken () : Token ;
52- return new HeaderParameter (KnownHeaders .Authorization , token );
51+ Token = string .IsNullOrEmpty (Token ) ? await GetToken () : Token ;
52+ return new HeaderParameter (KnownHeaders .Authorization , Token );
5353 }
5454}
5555```
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public JwtAuthenticator(string accessToken) : base(GetToken(accessToken)) { }
2828 [ PublicAPI ]
2929 public void SetBearerToken ( string accessToken ) => Token = GetToken ( accessToken ) ;
3030
31- static string GetToken ( string accessToken ) => $ "Bearer { Ensure . NotEmpty ( accessToken , nameof ( accessToken ) ) } ";
31+ static string GetToken ( string accessToken ) => Ensure . NotEmpty ( accessToken , nameof ( accessToken ) ) . StartsWith ( "Bearer " ) ? accessToken : $ "Bearer { accessToken } ";
3232
3333 protected override ValueTask < Parameter > GetAuthenticationParameter ( string accessToken )
3434 => new ( new HeaderParameter ( KnownHeaders . Authorization , accessToken ) ) ;
Original file line number Diff line number Diff line change @@ -34,6 +34,20 @@ public async Task Can_Set_ValidFormat_Auth_Header() {
3434 Assert . True ( authParam . Type == ParameterType . HttpHeader ) ;
3535 Assert . Equal ( _expectedAuthHeaderContent , authParam . Value ) ;
3636 }
37+
38+ [ Fact ]
39+ public async Task Can_Set_ValidFormat_Auth_Header_With_Bearer_Prefix ( ) {
40+ var client = new RestClient { Authenticator = new JwtAuthenticator ( $ "Bearer { _testJwt } ") } ;
41+ var request = new RestRequest ( ) ;
42+
43+ //In real case client.Execute(request) will invoke Authenticate method
44+ await client . Authenticator . Authenticate ( client , request ) ;
45+
46+ var authParam = request . Parameters . Single ( p => p . Name . Equals ( KnownHeaders . Authorization , StringComparison . OrdinalIgnoreCase ) ) ;
47+
48+ Assert . True ( authParam . Type == ParameterType . HttpHeader ) ;
49+ Assert . Equal ( _expectedAuthHeaderContent , authParam . Value ) ;
50+ }
3751
3852 [ Fact ]
3953 public async Task Check_Only_Header_Authorization ( ) {
You can’t perform that action at this time.
0 commit comments