Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code flow into main... #54

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: Nuget
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main", release-*, develop-* ]
branches: [ "main", release-*, develop ]
pull_request:
branches: [ "main", release-*, develop-* ]
branches: [ "main", release-*, develop ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
1 change: 1 addition & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
workflow: GitFlow/v1
commit-message-incrementing: MergeMessageOnly
assembly-file-versioning-format: '{Major}.{Minor}.{Patch}.{CommitsSinceVersionSource ?? 0}'
assembly-informational-format: '{Major}.{Minor}.{Patch}.{CommitsSinceVersionSource ?? 0}-{BranchName}-{Sha}'
3 changes: 1 addition & 2 deletions src/FishyFlip/ATProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ public async Task<string> GenerateOAuth2AuthenticationUrlAsync(string clientId,
throw new OAuth2Exception("Proof key is required for OAuth2 sessions.");
}

await oAuth2SessionManager.StartSessionAsync(session, clientId, instanceUrl);
return await Task.FromResult<Session?>(oAuth2SessionManager.Session);
return (await oAuth2SessionManager.StartSessionAsync(session, clientId, instanceUrl)).Session;
}

/// <summary>
Expand Down
4 changes: 0 additions & 4 deletions src/FishyFlip/FishyFlip.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" />
<PackageReference Include="IpfsShipyard.Ipfs.Core" />
<PackageReference Include="PeterO.Cbor" />
Expand Down
18 changes: 14 additions & 4 deletions src/FishyFlip/OAuth2SessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public OAuth2SessionManager(ATProtocol protocol)
/// <param name="cancellationToken">Cancellation Token.</param>
/// <exception cref="OAuth2Exception">Thrown if missing OAuth2 information.</exception>
/// <returns>Task.</returns>
public Task StartSessionAsync(AuthSession session, string clientId, string? instanceUrl = default, CancellationToken cancellationToken = default)
public Task<AuthSession> StartSessionAsync(AuthSession session, string clientId, string? instanceUrl = default, CancellationToken cancellationToken = default)
{
instanceUrl ??= Constants.Urls.ATProtoServer.SocialApi;
var options = new OidcClientOptions
Expand Down Expand Up @@ -96,7 +96,7 @@ public Task StartSessionAsync(AuthSession session, string clientId, string? inst
this.delegatingHandler.TokenRefreshed += this.DelegatingHandler_TokenRefreshed;

this.SetSession(session.Session);
return Task.CompletedTask;
return Task.FromResult(session);
}

/// <summary>
Expand Down Expand Up @@ -242,12 +242,12 @@ public void Dispose()
var refreshResult = await this.oidcClient.RefreshTokenAsync(this.session!.RefreshJwt, backChannelParameters: null, scope: null, cancellationToken: cancellationToken);
if (refreshResult.IsError)
{
this.logger?.LogError($"Failed to refresh token: {refreshResult.Error} {refreshResult.ErrorDescription}");
throw new OAuth2Exception($"Failed to refresh token: {refreshResult.Error} {refreshResult.ErrorDescription}");
}

if (this.session is null)
{
throw new NullReferenceException("Session should not be null if RefreshToken handler is enabled");
throw new OAuth2Exception("Session should not be null if RefreshToken handler is enabled");
}

lock (this.session)
Expand Down Expand Up @@ -287,6 +287,16 @@ private void DelegatingHandler_TokenRefreshed(object? sender, TokenRefreshedEven
throw new NullReferenceException("Session should not be null if RefreshToken handler is enabled");
}

if (string.IsNullOrEmpty(e.RefreshToken))
{
throw new OAuth2Exception("RefreshToken is null or empty.");
}

if (string.IsNullOrEmpty(e.AccessToken))
{
throw new OAuth2Exception("AccessToken is null or empty.");
}

lock (this.session)
{
this.session = new Session(this.session.Did, this.session.DidDoc, this.session.Handle, null, e.AccessToken, e.RefreshToken);
Expand Down
1 change: 1 addition & 0 deletions src/FishyFlip/Tools/HttpClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ private static async Task<ATError> CreateError(HttpResponseMessage message, Json
ErrorDetail? detail = default;
if (string.IsNullOrEmpty(response))
{
detail = new ErrorDetail("HTTP Error", message.ReasonPhrase ?? string.Empty);
atError = new ATError((int)message.StatusCode, detail);
}
else
Expand Down