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)); }
public object Get() { ApiKey key = GetCurrentApiKey(); if (key == null) { return(NotFound()); } return(AccessTokenHelper.ToJsonModel(key)); }
public object Get(string id) { SetAntiForgeryTokens(); ApiKey key = _keyProvider.GetKey(id); if (key == null) { return(NotFound()); } return(AccessTokenHelper.ToJsonModel(key)); }
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))); }
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) }); }