Beispiel #1
0
        public async Task <EmbyToken> GetEmbyToken(EmbyLogin login)
        {
            if (!string.IsNullOrEmpty(login?.Password) && !string.IsNullOrEmpty(login.UserName))
            {
                try
                {
                    var token = await _embyClient.AuthenticateUserAsync(login.UserName, login.Password, login.Address);

                    return(new EmbyToken
                    {
                        Token = token.AccessToken,
                        Username = token.User.ConnectUserName,
                        IsAdmin = token.User.Policy.IsAdministrator,
                        Id = token.User.Id
                    });
                }
                catch (Exception e)
                {
                    Log.Error("Username or password are wrong, user should try again with other credentials!");
                    Log.Error($"Message: {e.Message}");
                    throw new BusinessException("TOKEN_FAILED");
                }
            }

            Log.Error("Username or password are empty, no use to try a login!");
            throw new BusinessException("TOKEN_FAILED");
        }