ServiceStack user user authentication

Does anyone have a real example of how to use int RefId as suggested in this question ?

I am trying to get authentication, but I need to get married to userAuth data with my own user table. The problem is that I have no idea how to pass an additional parameter to the "/ register" method. I suppose I'm looking for an event, such as "OnAddUser", that will allow me to add some additional parameters to the mix.

I was able to quickly finish the user registration, it was very simple. Maybe the problem was that it was too easy? I see that this works, but I cannot figure out how to get between it and the database.

Either the dictionary approach or the RefId approach will probably work for me, it’s just not clear to me how to use this.

Is it possible to completely override the creator user? I found this code:

MyServices.cs

which looks like creating a user instead of "/ register", but there are other articles that suggest that you cannot override DTO ServiceStack, you should use the default tables.

+4
source share
1 answer

, RegisterService , . DTO , .

DTO, ?querystring, ,

var myParam = base.Request.QueryString["myParam"];

- Auth.

TechStacks CustomAuthUserSession:

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

    public string GithubProfileUrl { get; set; }
    public string TwitterProfileUrl { get; set; }

    public override void OnAuthenticated(IServiceBase authService, 
        IAuthSession session, 
        IAuthTokens tokens, 
        Dictionary<string, string> authInfo)
    {
        base.OnAuthenticated(authService, session, tokens, authInfo);
        var appSettings = authService.TryResolve<IAppSettings>();
        var userAuthRepo = authService.TryResolve<IAuthRepository>();
        var userAuth = userAuthRepo.GetUserAuth(session, tokens);
        var dbConnectionFactory = authService.TryResolve<IDbConnectionFactory>();
        foreach (var authTokens in session.ProviderOAuthAccess)
        {
            if (authTokens.Provider.ToLower() == "github")
            {
                GithubProfileUrl = session.GetProfileUrl();
            }
            if (authTokens.Provider.ToLower() == "twitter")
            {
                TwitterProfileUrl = session.GetProfileUrl();
                if (appSettings.GetList("TwitterAdmins").Contains(session.UserName) 
                    && !session.HasRole(RoleNames.Admin))
                {
                    userAuthRepo.AssignRoles(userAuth, roles:new[]{RoleNames.Admin});
                }
            }

            DefaultProfileUrl = GithubProfileUrl ?? TwitterProfileUrl;
            using (var db = dbConnectionFactory.OpenDbConnection())
            {
                var userAuthInstance = db.Single<CustomUserAuth>(x => 
                    x.Id == this.UserAuthId.ToInt());
                if (userAuthInstance != null)
                {
                    userAuthInstance.DefaultProfileUrl = this.DefaultProfileUrl;
                    db.Save(userAuthInstance);
                }
            }
        }
    }
}

URL- GitHub Twitter. Admin TwitterAdmins AppSetting, Twitter. , URL- CustomUserAuth POCO .

TechStacks ServiceStack CustomUserAuth OrmLiteAuthRepository:

var authRepo = new OrmLiteAuthRepository<CustomUserAuth, UserAuthDetails>(dbFactory);
container.Register<IUserAuthRepository>(authRepo);
authRepo.InitSchema();

CustomUserAuth UserAuth .

+2

All Articles