Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Nov 22, 2023
1 parent 949f067 commit 00ba744
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
26 changes: 26 additions & 0 deletions src/FishyFlip/ATProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,32 @@ internal void OnSubscribedRepoMessageInternal(SubscribedRepoEventArgs e)
/// <param name="session"><see cref="Session"/>.</param>
internal void OnUserLoggedIn(Session session)
{
if (this.options.UseServiceEndpointUponLogin)
{
var logger = this.options?.Logger;
var serviceUrl = session.DidDoc?.Service?.FirstOrDefault()?.ServiceEndpoint;
if (string.IsNullOrEmpty(serviceUrl))
{
logger?.LogWarning($"UseServiceEndpointUponLogin enabled, but session missing Service Endpoint.");
}
else
{
var result = Uri.TryCreate(serviceUrl, UriKind.Absolute, out Uri? uriResult);
if (!result || uriResult is null)
{
logger?.LogWarning($"UseServiceEndpointUponLogin enabled, but session missing Service Endpoint.");
}
else
{
this.Options.Url = uriResult;
logger?.LogInformation($"UseServiceEndpointUponLogin enabled, switching to {uriResult}.");
this.Options.Session = session;
this.UpdateOptions(this.Options);
return;
}
}
}

if (this.sessionManager is null)
{
this.sessionManager = new SessionManager(this);
Expand Down
23 changes: 1 addition & 22 deletions src/FishyFlip/SessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,13 @@ internal void SetSession(Session session)
this.UpdateBearerToken(session);

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

if (!this.protocol.Options.AutoRenewSession)
{
this.logger?.LogDebug("AutoRenewSession is disabled.");
return;
}

if (this.protocol.Options.UseServiceEndpointUponLogin)
{
var serviceUrl = session.DidDoc?.Service?.FirstOrDefault()?.ServiceEndpoint;
if (!string.IsNullOrEmpty(serviceUrl))
{
this.logger?.LogWarning($"UseServiceEndpointUponLogin enabled, but session missing Service Endpoint.");
}
else
{
var result = Uri.TryCreate(serviceUrl, UriKind.Absolute, out Uri? uriResult);
if (!result || uriResult is null)
{
this.logger?.LogWarning($"UseServiceEndpointUponLogin enabled, but session missing Service Endpoint.");
}
else
{
this.protocol.Options.Url = uriResult;
this.logger?.LogInformation($"UseServiceEndpointUponLogin enabled, switching to {uriResult}.");
}
}
}

this.logger?.LogDebug("AutoRenewSession is enabled.");
this.timer ??= new System.Timers.Timer();

Expand Down

0 comments on commit 00ba744

Please sign in to comment.