Decode JWT using Appsync Resolver Mapping Template - aws-appsync

I have stored a custom claim the IdToken and I send the whole token into the graphql interface using a custom header called "customs". How can I decode it to an object in a resolver and get the value of the claim?
I have tried this:
#set($myClaim=$context.request.headers.get('customs').myClaim)
I didn't expect this code to work, because the header is encoded, but I saw it in an example and I post it here so you can get a picture of what I am trying to do.

Related

Talend tREST component cookie extract

I'm working on a pretty straight forward proof of concept to log-in via a POST action using Talend.
From the application side, I use a POST with a body to then receive a cookie. However, I'm at a loss for how to get the cookie details from the response of the endpoint.
In my forum lurking, there appear to be two approaches: one using tREST, the other using tRESTClient.
Using tREST, I can successfully post to the endpoint, but I can not appear to retrieve the response header or body:
This is the tREST component properties:
The cookie passed from this call needs to be recycled into subsequent calls in order for them to authenticate.
I'm hoping to understand how to get the Cookie out and passed along, either with tREST or tRESTClient. My issue with tRESTClient is that I do not have a way to pass the body to that component.
Any thoughts?
On your last point - you can pass the body to tRestClient by having a flow going into tRestClient. That flow can have a "string" field containing the body in json format, and that field will need to map to the "string" column in the component input schema.
If, in your case, you do not already have a flow containing the body, you can generate it by using the tFixedFlowInput component.

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

keycloak client protocol mapper (script mapper) to add request header into token

When I'm requesting a token from keycloak I want a specific header value (or extra form data) that was supplied in the request to be put in the JWT payload of the generated token. I've tried using a Script Mapper to get access to header values but I can't see how to get access to header values or data in the form data sent in any of the available script variables: user, realm, userSession, keyclockSession.
You can get access to request headers using keycloakSession object, something like
keycloakSession.getContext().getRequestHeaders().getRequestHeader("User-Agent")
If you check the code for DefaultEvaluationContext class, that is how they add the User-Agent header.

Get non file body from multipart/form-data using AWS API Gateway and Lambda

I am trying to get the form data from a multipart/form-data POST to my ASW Lambda web service via API Gateway.
The HTTP POST has Content-Type "multipart/form-data" and body that is URL encoded. File data is also sent in this post (hence the multipart, I guess).
The web service needs to integrate with a thirdparty service, so changing the format of the POST isn't really an option.
I have seen this thread talking about converting the URL encoded data to JSON object for use in Lambda, but this doesn't do the trick.
I have also tried setting the Integration Request -> Mapping Templates for content type multipart/form-data to Input passthrough. This didn't help either.
I did come across another question about uploading a file using multipart/form-data, but since I'm not interested in the file, just the body, that answer didn't help.
Below find screenshot (sorry) of the captured post via runscope.
If the goal is to use Lambda, you'll need to pass valid JSON to the function. Currently there isn't a way to JSON-ify data inside Api Gateway that comes in as non-JSON data.
Our short term fix (on our backlog) is to provide a variable in the mapping templates to grab the raw input of the request. That way you could do a simple JSON conversion using a template like:
{
"body" : "$input.body"
}
or something like that.
Check out the mapping template reference for more info: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
Edit 4/7 - feature has been released as $input.body

Retrieve Pyramid's auth_tkt via HTTP response headers on mobile client

I am writing a mobile iOS application, which communicates with a Pyramid app on the backend. I am currently using Pyramid's built-in AuthTktAuthenticationPolicy.
I've met some speed bumps while attempting to authenticate via a mobile client (iPhone). For starters, how would I send and retrieve the auth_tkt cookie that is set by Pyramid.
I understand how this works with a web browser, but, if I want to send this "auth_tkt cookie" in the HTTP response, how can I accomplish this? How do I actually get the auth_tkt secret string. For example, what if I'd like to return it in the JSON body or a custom header of my choosing rather than as the cookie set by Pyramid's remember function?
Secondly, in future requests sent by the client what header do I set with the auth_tkt secret string so that Pyramid recognizes it and appropriately authenticates the client?
Using the Pyramid Helper Classes here, it looks like you can create your own auth_tkt and access it as well. Example from docs:
token = AuthTicket('sharedsecret', 'username',
os.environ['REMOTE_ADDR'], tokens=['admin'])
val = token.cookie_value()
The headers is a webob ResponseHeaders object, it derives from webob multidict. You can get it value by using this:
set_cookie = request.response.headers['set-cookie']
You can refer this link: webob multidict