Beispiel #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));
        }
Beispiel #2
0
        public object Get()
        {
            ApiKey key = GetCurrentApiKey();

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

            return(AccessTokenHelper.ToJsonModel(key));
        }
Beispiel #3
0
        public object Get(string id)
        {
            SetAntiForgeryTokens();

            ApiKey key = _keyProvider.GetKey(id);

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

            return(AccessTokenHelper.ToJsonModel(key));
        }
Beispiel #4
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)));
        }
Beispiel #5
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) });
        }