Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move data sent to nuts-pxp from headers to body #495

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions api/transfer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -201,14 +202,25 @@ func (w Wrapper) UpdateTransferNegotiationStatus(ctx echo.Context, transferID st
func (w Wrapper) NotifyTransferUpdate(ctx echo.Context, taskID string) error {
// This gets called by a transfer sending XIS to inform the local node there's FHIR tasks to be retrieved.
// The PEP added introspection result to the X-Userinfo header
introspectionResult := ctx.Request().Header.Get("X-Userinfo")
//log.Errorf("X-Userinfo: %s", introspectionResult)

if introspectionResult == "" {
b64IntrospectionResult := ctx.Request().Header.Get("X-Userinfo")
//log.Errorf("X-Userinfo: %s", b64IntrospectionResult)
if b64IntrospectionResult == "" {
return errors.New("missing X-Userinfo header")
}

// b64 -> json string
introspectionResult, err := base64.URLEncoding.DecodeString(b64IntrospectionResult)
if err != nil {
return fmt.Errorf("failed to base64 decode X-Userinfo header: %w", err)
}

// json string -> map
target := map[string]interface{}{}
_ = json.Unmarshal([]byte(introspectionResult), &target)
err = json.Unmarshal(introspectionResult, &target)
if err != nil {
return fmt.Errorf("failed to unmarshal X-Userinfo header: %w", err)
}

// client_id for senderDID and sub for customerDID
senderDID := target["client_id"].(string)
customerDID := target["sub"].(string)
Expand Down
3 changes: 1 addition & 2 deletions docker-compose/left/config/pep/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ http {
location /_oauth2_authorize {
internal;
proxy_method POST;
proxy_set_header request $request;
proxy_set_header X-Userinfo $http_x_userinfo;
proxy_set_header Content-Type "application/json";
proxy_pass http://pip-left/v1/data;
}
}
Expand Down
18 changes: 15 additions & 3 deletions docker-compose/left/config/pep/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function introspectAccessToken(r) {
const introspection = JSON.parse(reply.responseBody);
if (introspection.active === true) {
//dpop(r, introspection.cnf)
r.headersOut['X-Userinfo'] = reply.responseBody;
r.headersOut['X-Userinfo'] = btoa(reply.responseBody);
r.return(200);
} else {
r.return(403);
Expand All @@ -31,13 +31,25 @@ function introspectAccessToken(r) {
function authorize(r) {
// const xUserinfo = r.headersIn['X-Userinfo'];
// const requestLine = r.request
const input =
JSON.stringify({
"input": {
"request": {
"method": r.variables.request_method,
"path": r.variables.request_uri, // original non-normalized request_uri, may need some processing in more complex situations
"headers": {
"X-Userinfo": r.headersIn["X-Userinfo"]
}
}
}
});
r.subrequest("/_oauth2_authorize",
{ method: "POST"},
{ method: "POST", body: input},
function(reply) {
if (reply.status === 200) {
r.error(reply.responseBody);
const authResult = JSON.parse(reply.responseBody);
if (authResult.allow === true) {
if (authResult.result.allow === true) {
r.return(200);
} else {
r.return(403);
Expand Down
3 changes: 1 addition & 2 deletions docker-compose/right/config/pep/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ http {
location /_oauth2_authorize {
internal;
proxy_method POST;
proxy_set_header request $request;
proxy_set_header X-Userinfo $http_x_userinfo;
proxy_set_header Content-Type "application/json";
proxy_pass http://pip-right/v1/data;
}
}
Expand Down
19 changes: 16 additions & 3 deletions docker-compose/right/config/pep/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function introspectAccessToken(r) {
const introspection = JSON.parse(reply.responseBody);
if (introspection.active === true) {
//dpop(r, introspection.cnf)
r.headersOut['X-Userinfo'] = reply.responseBody;
r.headersOut['X-Userinfo'] = btoa(reply.responseBody);
r.return(200);
} else {
r.return(403);
Expand All @@ -31,13 +31,26 @@ function introspectAccessToken(r) {
function authorize(r) {
// const xUserinfo = r.headersIn['X-Userinfo'];
// const requestLine = r.request
const input =
JSON.stringify({
"input": {
"request": {
"method": r.variables.request_method,
"path": r.variables.request_uri, // original non-normalized request_uri, may need some processing in more complex situations
"headers": {
"X-Userinfo": r.headersIn["X-Userinfo"]
}
}

}
});
r.subrequest("/_oauth2_authorize",
{ method: "POST"},
{ method: "POST", body: input},
function(reply) {
if (reply.status === 200) {
r.error(reply.responseBody);
const authResult = JSON.parse(reply.responseBody);
if (authResult.allow === true) {
if (authResult.result.allow === true) {
r.return(200);
} else {
r.return(403);
Expand Down
Loading