iron-io / functions

IronFunctions - the serverless microservices platform by
https://iron.io
Apache License 2.0
3.18k stars 227 forks source link

How do I get authentication context(cookie or header) in my java main function? #666

Open sss0350 opened 6 years ago

sss0350 commented 6 years ago

Hello there, I'm trying to figure out how to I use iron-functions to get client cookie or header information(token) from my java class. Could you give me an example? (can't find one at current code track) At old time we will get httprequest / httpresponse object from servlet in web a standard web project. And try to get cookie and header there, just wondering how do we get from a pojo main function here? Since we will use cookie(entrypt) to do user verification with our other systems. Thank you! Gatsby

c0ze commented 6 years ago

hello @sss0350 ,

All headers should be available as ENV variables in your function, with the following format :

HEADER_{HTTP Header, uppercase, `-` replaced by `_`}
HEADER_ACCEPT_LANGUAGE
HEADER_AUTHORIZATION

etc.

functions inputs

Hope this helps !

sss0350 commented 6 years ago

Hey @c0ze,

I can get http header with System.getenv("HEADER_X") in java as you provided.

But how to I get cookies values ? I can't find a way to get it , since we need to rely on cookie to do some authorization. Could you give me a hint?

c0ze commented 6 years ago

hello @sss0350 !

I'm glad that you were able to access request headers ! You can use route configuration to add static headers as described here. Unfortunately there is no way to add headers dynamically at this point as you would need to in a cookie based authentication. What you can do is maybe write / add a server cookie to response object, and read it from the body (as opposed to from headers) from the client side.