-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from thefringeninja/auth
Support Bearer Tokens in User Credentials
- Loading branch information
Showing
9 changed files
with
52 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ on: | |
- oss-v* | ||
|
||
env: | ||
DOTNET_SDK_VERSION: 3.1.201 | ||
DOTNET_SDK_VERSION: 3.1.300 | ||
jobs: | ||
vulnerability-scan: | ||
runs-on: ubuntu-latest | ||
|
@@ -49,8 +49,6 @@ jobs: | |
shell: bash | ||
run: | | ||
docker pull docker.pkg.github.com/eventstore/eventstore/eventstore:${{ matrix.docker-tag }} | ||
docker tag docker.pkg.github.com/eventstore/eventstore/eventstore:${{ matrix.docker-tag }} \ | ||
eventstore/eventstore:${{ matrix.docker-tag }} | ||
- name: Install Dotnet | ||
uses: actions/[email protected] | ||
with: | ||
|
@@ -102,8 +100,7 @@ jobs: | |
- name: Dotnet Pack | ||
shell: bash | ||
run: | | ||
dotnet tool restore | ||
dotnet pack --configuration=Release --output=./packages /p:Version=$(dotnet tool run minver) \ | ||
dotnet pack --configuration=Release --output=./packages \ | ||
/p:NoWarn=NU5105 \ | ||
/p:RepositoryUrl=https://github.com/EventStore/EventStore-Client-Dotnet \ | ||
/p:RepositoryType=git | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,42 @@ | ||
using System; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
|
||
#nullable enable | ||
namespace EventStore.Client { | ||
public class UserCredentials { | ||
public readonly string Username; | ||
public readonly string Password; | ||
public string? Username => TryGetBasicAuth(0, out var value) ? value : null; | ||
public string? Password => TryGetBasicAuth(1, out var value) ? value : null; | ||
|
||
public UserCredentials(string username, string password) { | ||
Username = username; | ||
Password = password; | ||
private readonly AuthenticationHeaderValue _authorization; | ||
|
||
public UserCredentials(string username, string password) : this(new AuthenticationHeaderValue( | ||
Constants.Headers.BasicScheme, | ||
Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}")))) { | ||
} | ||
|
||
public UserCredentials(string authToken) : this(new AuthenticationHeaderValue(Constants.Headers.BearerScheme, | ||
authToken)) { | ||
} | ||
|
||
private UserCredentials(AuthenticationHeaderValue authorization) => _authorization = authorization; | ||
|
||
private bool TryGetBasicAuth(int index, out string? value) { | ||
value = null; | ||
|
||
if (_authorization.Scheme != Constants.Headers.BasicScheme) { | ||
return false; | ||
} | ||
|
||
var parts = Encoding.ASCII.GetString(Convert.FromBase64String(_authorization.Parameter)).Split(':'); | ||
if (parts.Length <= index) { | ||
return false; | ||
} | ||
|
||
value = parts[index]; | ||
return true; | ||
} | ||
|
||
public override string ToString() => _authorization.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters