stormpath / stormpath-nginx

A Stormpath integration written in Lua for the nginx web server.
Apache License 2.0
24 stars 7 forks source link

Also add 'x-stormpath-org-href' header if JWT contains 'org' element #7

Open vanjabucic opened 7 years ago

vanjabucic commented 7 years ago

When authenticating explicitly against an organization by supplying organizationNameKey=anOrganization parameter, the resulting JWT contains an 'org' element that points to that organization. We should inject that info into a header. ISS and SUB elements are already exposed:

ngx.req.set_header('x-stormpath-application-href', jwt.payload.iss)
ngx.req.set_header('x-stormpath-account-href', jwt.payload.sub)
edjiang commented 7 years ago

That's a great idea! Do you have a timeframe that you're working on? I can get this in for a near release, but a bit busy in the next two weeks.

vanjabucic commented 7 years ago

I was just thinking we could easily add it in:

getAccount(required)
  ...
  ngx.req.set_header('x-stormpath-application-href', jwt.payload.iss)
  ngx.req.set_header('x-stormpath-account-href', jwt.payload.sub)
  if(jwt.payload.org) then
     ngx.req.set_header('x-stormpath-org-href', jwt.payload.org)
  end
end

I will just modify our working copy until you publish this, so no rush.

Thanks.

edjiang commented 7 years ago

Cool. I think we'd want to use the full name x-stormpath-organization-href so if you use that instead of org would probably be best! Keep on the lookout for an update =]