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 25
25
uses : actions/checkout@v3
26
26
-
27
27
name : Setup .NET
28
- uses : actions/setup-dotnet@v2
28
+ uses : actions/setup-dotnet@v3
29
29
with :
30
30
dotnet-version : ' 6.0'
31
31
-
Original file line number Diff line number Diff line change 15
15
uses : actions/checkout@v3
16
16
-
17
17
name : Setup .NET
18
- uses : actions/setup-dotnet@v2
18
+ uses : actions/setup-dotnet@v3
19
19
with :
20
20
dotnet-version : ' 6.0'
21
21
-
Original file line number Diff line number Diff line change @@ -48,8 +48,8 @@ public class TwitterAuthenticator : AuthenticatorBase {
48
48
}
49
49
50
50
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 );
53
53
}
54
54
}
55
55
```
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public JwtAuthenticator(string accessToken) : base(GetToken(accessToken)) { }
28
28
[ PublicAPI ]
29
29
public void SetBearerToken ( string accessToken ) => Token = GetToken ( accessToken ) ;
30
30
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 } ";
32
32
33
33
protected override ValueTask < Parameter > GetAuthenticationParameter ( string accessToken )
34
34
=> 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() {
34
34
Assert . True ( authParam . Type == ParameterType . HttpHeader ) ;
35
35
Assert . Equal ( _expectedAuthHeaderContent , authParam . Value ) ;
36
36
}
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
+ }
37
51
38
52
[ Fact ]
39
53
public async Task Check_Only_Header_Authorization ( ) {
You can’t perform that action at this time.
0 commit comments