private Task <IUserAuth> GetUserAuthAsync(IRedisClientFacadeAsync redis, string userAuthId, CancellationToken token = default) { if (userAuthId == null || !long.TryParse(userAuthId, out var longId)) { return(null); } return(redis.AsAsync <IUserAuth>().GetByIdAsync(longId, token)); }
private async Task <IUserAuth> GetUserAuthAsync(IRedisClientFacadeAsync redis, IAuthSession authSession, IAuthTokens tokens, CancellationToken token = default) { if (!authSession.UserAuthId.IsNullOrEmpty()) { var userAuth = await GetUserAuthAsync(redis, authSession.UserAuthId, token).ConfigAwait(); if (userAuth != null) { return(userAuth); } } if (!authSession.UserAuthName.IsNullOrEmpty()) { var userAuth = await GetUserAuthByUserNameAsync(authSession.UserAuthName, token).ConfigAwait(); if (userAuth != null) { return(userAuth); } } if (tokens == null || tokens.Provider.IsNullOrEmpty() || tokens.UserId.IsNullOrEmpty()) { return(null); } var oAuthProviderId = await GetAuthProviderByUserIdAsync(redis, tokens.Provider, tokens.UserId, token).ConfigAwait(); if (!oAuthProviderId.IsNullOrEmpty()) { var oauthProvider = await redis.AsAsync <TUserAuthDetails>().GetByIdAsync(oAuthProviderId, token).ConfigAwait(); if (oauthProvider != null) { return(await redis.AsAsync <IUserAuth>().GetByIdAsync(oauthProvider.UserAuthId, token)); } } return(null); }
private async Task <IUserAuth> GetUserAuthByUserNameAsync(IRedisClientFacadeAsync redis, string userNameOrEmail, CancellationToken token = default) { if (userNameOrEmail == null) { return(null); } var isEmail = userNameOrEmail.Contains("@"); var userId = isEmail ? await redis.GetValueFromHashAsync(IndexEmailToUserId, userNameOrEmail, token).ConfigAwait() : await redis.GetValueFromHashAsync(IndexUserNameToUserId, userNameOrEmail, token).ConfigAwait(); return(userId == null ? null : await redis.AsAsync <IUserAuth>().GetByIdAsync(userId, token).ConfigAwait()); }