API Gateway Update Request Body with context variable from custom authorizer in Smithy - aws-api-gateway

I'm trying to update my POST request body with a field from the authorizer context. How can I achieve this if I'm defining my models and service in Smithy.
Thanks
Can't find any resources for this.

Related

Routing message from AWS API Gateway to SQS regarding URL path

I need to route a message from API Gateway to a specific queue regarding URL Path.
By example:
/queues/{queueId} -> API GW routes /queues/queue1 URL to SQS queue1
Is it possible to do it "simply" only with API GW config or do I need to use a lambda to make the routing to the right queue ? or any other solution ?
It is possible to do that.
While configuring integration on Path Override you need define it like 12345678/{queueId} (12345678 is your account id).
Then you need to define URL PATH Parameters
Name queueId, Mapped from method.request.path.queueId
Expand HTTP headers add new Header with Name Content-Type, Mapped from as 'application/x-www-form-urlencoded'
Add a Mapping Templates as Content-Type application/json and template body as Action=SendMessage&MessageBody=$input.body

Add protocol mapper to client via keycloak REST API

By the latest Keycloak's REST API documentation https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_protocol_mappers_resource, I can't find enough information to add a new protocol mapping with mapper type 'Audience' by REST API. I am able to do it by Keycloak UI (See attached) and now I would like to automate it to our DevOps pipeline.
I wonder if the only way to find out the json content is to look at the request payload of the POST Request suggested by this post:
Where are all of the Keycloak Protocol Mapper Config Options documented?
There are also some information on keycloak ui : in the browser's debugger console (mapper types)
You need to issue an HTTP POST request to http://<host>:<port>/admin/realms/<realm_name>/clients/<client_id>/protocol-mappers/models
with a payload like this
{
"protocol":"openid-connect",
"config": {
"id.token.claim":"false",
"access.token.claim":"true",
"included.client.audience":"admin-cli",
"included.custom.audience":"custom_audience"
},
"name":"Audience Mapper",
"protocolMapper":"oidc-audience-mapper"
}

How to use one REST API RESPONSE property, and use it in another REST API header property

I would like to know how to property transfer from one REST API to another REST API?
I worked on the property transfer with the JSON format, but I need to know how to transfer the one REST API response property and use it in the header?
let me explain this using the below scenario:
Admin get the User object by API
Save apiKey from the user object
Call the action on user behalf(By set Authorization Header to Basic with the user apiKey)
To accomplish these steps in soapUI You have to:
Define apiKey in Custom Properties in TestCase
Call resource that returns a User object
Save apiKey property to TestCase.apiKey via property transfer or Groovy Step
Reuse TestCase.apiKey in your nest REST Request step by expanding it via Basic ${=(testCase.getPropertyValue("apiKey")+":").bytes.encodeBase64()}
Hope that helps

How do I implement dry run option to a REST api so I have a way of knowing it is implemented?

In my system, I have multiple services exposing REST apis for their resources. A specific service on the system needs to make rest calls to other services in dry-run mode in specific circumstances just to do validation. Even though the body of the request has meaningful payload for the api, nothing will be persisted, no states will be changed and no messages will be sent. The tricky part is that if this service calls a REST api which didn't implement dry-run mode, it will modify the resource instead of just validating. I need a way to make dry-run requests only if the receiving service implemented dry-run in its api, otherwise the request must fail.
I had these ideas so far:
Passing a query parameter
I could pass a flag as a query parameter but the request still goes through if the api doesn't know of the parameter.
POST /resource?dry-run=true
Passing a flag in header
Similar to query parameter, unknown header fields are ignored.
Exposing a dry-run api just for validating
This solution works as I can verify dry-run version of the URL exists or not but I don't want to expose more endpoints just for validation
POST /resource
POST /resource/dry-run
PUT /resource/{id}
PUT /resource/{id}/dry-run
Inject the flag to the body of resource
This looks to be a solution but when the api doesn't support this field, JSON serialization will fail. In that case, I can't tell whether it is because dry-run is not supported by the api or there is actually a problem in the body. Also, it doesn't feel right since dry-run is not a part of the resource.
POST /resource
{
"dry-run":true,
...
...
}
Is there a better way to implement a dry-run feature to REST api where the request will fail if the service have not implemented it?
The headers way
There does not seem to be a "correct" answer for this. That being said, I would go with the headers way.
You can easily block off unknown headers as preflight checks. You can change the allow list of headers for you service to block off headers that are not used by the service.
Access-Control-Allow-Headers: [<header-name>[, <header-name>]*]
Access-Control-Allow-Headers: *
To see the list of headers allowed by your service, make a call to it and check the response headers and search for Access-Control-Allow-Headers header field.
Let's say you have three services, Cat, Dog and Animal. Animal being the caller service which calls the Cat service and Dog service.
Dog -> Access-Control-Allow-Headers: [....,"X-Request-Dry-Run",..] // dog accepts the header
Cat -> Access-Control-Allow-Headers: [.....] // cat doesn't accept the 'dry-run' header
Now when caller calls the Cat service which X-Request-Dry-Run: true header, it gets a request error.
MDN Ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
Comparisons
Passing a query parameter
could pass a flag as a query parameter but the request still goes through if the api doesn't know of the parameter.
It's generally not a convention to mix post body and query params in a post request.
Exposing a dry-run api just for validating
This solution works as I can verify dry-run version of the URL exists or not but I don't want to expose more endpoints just for validation
APIs have clashing paths.
Inject the flag to the body of resource
This looks to be a solution but when the api doesn't support this field, JSON serialization will fail. In that case, I can't tell whether it is because dry-run is not supported by the api or there is actually a problem in the body. Also, it doesn't feel right since dry-run is not a part of the resource.
Agreed

Create a DataContext and provide an API Key

i need some help with the following:
i have a wcf data service with some api authorization mechanism.
that works, if i enter the service url in the browser. it validates the api key and gives me data.
in another project, i added the service url as a service reference and like to instanciate a EntityFramework DataContext object, but what i wanted was, that the given URI to the constructor of that DataContext needs to have an api-key in there.
if i try to pass that api key as a query-parameter, i get an error: "Expected an absolute, well formed http URL without a query or fragment."
ok that message points out clearly what i did wrong, but how can i get the apiKey included?
greets,
chris
I've found the answer on social.msdn.com. Basically, you need to use the AddQueryOption method of a resource proxy, like:
SomeService.SomeResource.AddQueryOption("apikey", "1234")