Skip to content

Commit

Permalink
Update CustomAuthUserSession.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jan 30, 2024
1 parent a030388 commit 57a71f0
Showing 1 changed file with 0 additions and 41 deletions.
41 changes: 0 additions & 41 deletions TechStacks.ServiceInterface/CustomAuthUserSession.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,18 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using ServiceStack;
using ServiceStack.Auth;
using ServiceStack.Configuration;
using ServiceStack.Data;
using ServiceStack.DataAnnotations;
using ServiceStack.OrmLite;
using TechStacks.Data;
using TechStacks.ServiceModel.Types;

namespace TechStacks.ServiceInterface;

public class CustomUserSession : AuthUserSession
{
public string GithubProfileUrl { get; set; }

public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
var dbFactory = authService.TryResolve<IDbConnectionFactory>();
var userId = session.UserAuthId.ToInt();

foreach (var authTokens in session.ProviderOAuthAccess)
{
if (authTokens.Provider.ToLower() == "github")
{
if (authInfo != null && authInfo.TryGetValue("avatar_url", out var avatarUrl))
{
GithubProfileUrl = avatarUrl;
}
}

ProfileUrl = GithubProfileUrl;

using var db = dbFactory.OpenDbConnection();
var userActivity = db.SingleById<UserActivity>(userId);
if (userActivity == null)
{
db.Insert(new UserActivity
{
Id = userId,
UserName = session.UserName,
Created = DateTime.UtcNow,
Modified = DateTime.UtcNow,
});
}
}
}
}

public class AdditionalUserClaimsPrincipalFactory(
Expand All @@ -74,7 +35,6 @@ public override async Task<ClaimsPrincipal> CreateAsync(ApplicationUser user)
}
}


public class CustomUserAuth : UserAuth
{
public string DefaultProfileUrl { get; set; }
Expand All @@ -95,4 +55,3 @@ public class CustomUserAuth : UserAuth

public string CreatedBy { get; set; }
}

0 comments on commit 57a71f0

Please sign in to comment.