File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
src/Docker.DotNet.BasicAuth Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,27 @@ internal class BasicAuthHandler : DelegatingHandler
66
77 private readonly MaybeSecureString _password ;
88
9+ private readonly Lazy < AuthenticationHeaderValue > _authHeader ;
10+
911 public BasicAuthHandler ( MaybeSecureString username , MaybeSecureString password , HttpMessageHandler httpMessageHandler )
1012 : base ( httpMessageHandler )
1113 {
1214 _username = username . Copy ( ) ;
1315 _password = password . Copy ( ) ;
16+
17+ _authHeader = new Lazy < AuthenticationHeaderValue > ( ( ) =>
18+ {
19+ var credentials = $ "{ _username } :{ _password } ";
20+ var bytes = Encoding . ASCII . GetBytes ( credentials ) ;
21+ var base64 = Convert . ToBase64String ( bytes ) ;
22+ return new AuthenticationHeaderValue ( "Basic" , base64 ) ;
23+ } ) ;
24+ }
25+
26+ protected override Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , CancellationToken cancellationToken )
27+ {
28+ request . Headers . Authorization = _authHeader . Value ;
29+ return base . SendAsync ( request , cancellationToken ) ;
1430 }
1531
1632 protected override void Dispose ( bool disposing )
You can’t perform that action at this time.
0 commit comments