예제 #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
        private void ConfigureAccessTokens()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.AccessTokensResource.Guid, $"{Defines.ACCESSTOKENS_PATH}/{{id?}}", new { controller = "AccessTokens" });

            Environment.Hal.ProvideLink(Defines.AccessTokensResource.Guid, "self", t => new { href = AccessTokenHelper.GetLocation(t.id) });
            Environment.Hal.ProvideLink(Defines.ApiKeysResource.Guid, "access_token", k => new { href = AccessTokenHelper.GetLocation(k.id) });
        }