예제 #1
0
        public async Task <object> Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            if (model.api_key == null || model.api_key.id == null)
            {
                throw new ApiArgumentException("api_key");
            }

            string apikeyId = DynamicHelper.Value(model.api_key.id);

            ApiKey key = _keyProvider.GetKey(apikeyId);

            if (key == null)
            {
                return(NotFound());
            }

            // Renew the token
            string token = await _keyProvider.RenewToken(key);

            //
            // Create response
            dynamic obj = AccessTokenHelper.ToJsonModel(new ApiToken()
            {
                Token = token, Key = key
            });

            return(Created(AccessTokenHelper.GetLocation(key.Id), obj));
        }
예제 #2
0
        public async Task <object> Post()
        {
            ApiKey key = GetCurrentApiKey();

            if (key == null)
            {
                return(NotFound());
            }

            // Renew the key
            ApiToken newKey = await _keyProvider.RenewToken(key);

            return(Created(Request.RequestUri.PathAndQuery,
                           AccessTokenHelper.ToJsonModel(newKey)));
        }
        public async Task <IActionResult> RefreshToken()
        {
            var form = await Request.ReadFormAsync();

            ApiKey key = _keyProvider.GetKey(form["id"]);

            if (key == null)
            {
                return(NotFound());
            }

            string token = await _keyProvider.RenewToken(key);

            return(View("Index", new {
                Keys = await GetAllKeys(),
                NewToken = new {
                    Purpose = key.Purpose,
                    Value = token
                }.ToExpando()
            }.ToExpando()));
        }