public async Task <IActionResult> ListTokens()
        {
            var model  = new TokensViewModel();
            var tokens = await _TokenRepository.GetTokensByStoreIdAsync(StoreData.Id);

            model.StatusMessage      = StatusMessage;
            model.StoreNotConfigured = StoreNotConfigured;
            model.Tokens             = tokens.Select(t => new TokenViewModel()
            {
                Label = t.Label,
                SIN   = t.SIN,
                Id    = t.Value
            }).ToArray();

            model.ApiKey = (await _TokenRepository.GetLegacyAPIKeys(StoreData.Id)).FirstOrDefault();
            if (model.ApiKey == null)
            {
                model.EncodedApiKey = "*API Key*";
            }
            else
            {
                model.EncodedApiKey = Encoders.Base64.EncodeData(Encoders.ASCII.DecodeData(model.ApiKey));
            }
            return(View(model));
        }
Beispiel #2
0
        async public Task <IActionResult> Tokens()
        {
            SetPageContent("tokens");

            var user = await _userEngine.CurrentUser(_userManager.GetUserId(User));

            var model = new TokensViewModel()
            {
                Items      = _projectEngine.GetUserTokens(user.Id),
                TokenCount = _userEngine.CurrentUserToken(_userManager.GetUserId(User))
            };

            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> ListTokens(string storeId)
        {
            var model  = new TokensViewModel();
            var tokens = await _TokenRepository.GetTokensByStoreIdAsync(storeId);

            model.StatusMessage = StatusMessage;
            model.Tokens        = tokens.Select(t => new TokenViewModel()
            {
                Facade = t.Facade,
                Label  = t.Label,
                SIN    = t.SIN,
                Id     = t.Value
            }).ToArray();
            return(View(model));
        }
        public async Task <IActionResult> ClearTokens([FromBody] TokensViewModel token)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            // Delete access token and refresh token in REDIS
            try
            {
                await LogicUnitOfWork.AccessTokenService.Delete(token.Access);  // Delete access token

                await LogicUnitOfWork.AccessTokenService.Delete(token.Refresh); // Delete refresh token
            }
            catch
            {
                return(BadRequest());  // send bad request if deletion token fail
            }
            return(Ok());
        }
        public async Task <IActionResult> Logout([FromBody] TokensViewModel token)
        {
            try
            {
                /*** Get logout every CookieAuthenticationScheme ***/
                await _signInManager.SignOutAsync();

                /*** Delete token every types ***/
                await LogicUnitOfWork.AccessTokenService.Delete(token.Access);  // Delete access token

                await LogicUnitOfWork.AccessTokenService.Delete(token.Refresh); // Delete refresh token
            }
            catch (Exception e)
            {
                /*** Return 400 when it has error ***/
                return(BadRequest(e));
            }
            /*** Return 200 when it not has error ***/
            return(Ok("You have successfully logged out")); // DISPLAYED WHEN USER HAS SUCCESSFULLY LOGGED OUT
        }