Skip to content

Commit

Permalink
Merge pull request #55 from drasticactions/fix-schema
Browse files Browse the repository at this point in the history
Update PasswordSession Schema to include session

+semver: fix
  • Loading branch information
drasticactions authored Sep 15, 2024
2 parents 28605cd + 0746ef8 commit 65dd4f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/FishyFlip/ATProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ public ATProtocol(ATProtocolOptions options)
/// </summary>
public AuthSession? OAuthSession => this.sessionManager is OAuth2SessionManager oAuth2SessionManager ? oAuth2SessionManager.OAuthSession : null;

/// <summary>
/// Gets the current PasswordSession session, if any is active.
/// </summary>
public AuthSession? PasswordSession => this.sessionManager is PasswordSessionManager passwordSessionManager ? passwordSessionManager.PasswordSession : null;

/// <summary>
/// Gets the current AuthSession.
/// </summary>
public AuthSession? AuthSession => this.sessionManager switch
{
PasswordSessionManager passwordSessionManager => passwordSessionManager.PasswordSession,
OAuth2SessionManager oAuth2SessionManager => oAuth2SessionManager.OAuthSession,
_ => null,
};

/// <summary>
/// Gets or sets the internal session manager.
/// </summary>
Expand Down
13 changes: 12 additions & 1 deletion src/FishyFlip/PasswordSessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal class PasswordSessionManager : ISessionManager
private System.Timers.Timer? timer;
private int refreshing;
private ILogger? logger;
private AuthSession? authSession;

/// <summary>
/// Initializes a new instance of the <see cref="PasswordSessionManager"/> class.
Expand Down Expand Up @@ -79,6 +80,11 @@ public PasswordSessionManager(ATProtocol protocol, Session session)
/// <inheritdoc/>
public HttpClient Client => this.client;

/// <summary>
/// Gets the password Auth Session.
/// </summary>
public AuthSession? PasswordSession => this.authSession;

/// <inheritdoc/>
public Task RefreshSessionAsync(CancellationToken cancellationToken = default)
=> this.RefreshTokenAsync(cancellationToken);
Expand Down Expand Up @@ -140,7 +146,12 @@ public void SetSession(Session session)

this.logger?.LogDebug($"Session set, {session.Did}");

this.SessionUpdated?.Invoke(this, new SessionUpdatedEventArgs(new AuthSession(session), this.protocol.Options.Url));
lock (this)
{
this.authSession = new AuthSession(session);
}

this.SessionUpdated?.Invoke(this, new SessionUpdatedEventArgs(this.authSession, this.protocol.Options.Url));

if (!this.protocol.Options.AutoRenewSession)
{
Expand Down

0 comments on commit 65dd4f8

Please sign in to comment.