Skip to content

Commit

Permalink
Merge pull request #54 from drasticactions/develop
Browse files Browse the repository at this point in the history
Code flow into main...

+semver: breaking
  • Loading branch information
drasticactions authored Sep 13, 2024
2 parents 82416f2 + 4302218 commit 28605cd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
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

0 comments on commit 28605cd

Please sign in to comment.