Skip to content

Commit 5a748b7

Browse files
Merge pull request #30 from NHSDigital/NPA-2166-spec-compliant-401-error
NPA-2166: Added FHIR compliant response for missing bearer token
2 parents 1fef75c + 72ce444 commit 5a748b7

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<!--
3+
This policy raises a 401 error response for an invalid or missing access token.
4+
5+
Raisefault policies stop the execution of the current flow and move to the error flow, which returns the error response defined here to the requesting application.
6+
7+
For more information on RaiseFault policies within Apigee see the following resource:
8+
* https://docs.apigee.com/api-platform/reference/policies/raise-fault-policy
9+
-->
210
<RaiseFault async="false" continueOnError="false" enabled="true" name="RaiseFault.401Unauthorized">
311
<DisplayName>RaiseFault.401Unauthorized</DisplayName>
412
<Properties/>
513
<FaultResponse>
614
<Set>
715
<Headers/>
8-
<Payload contentType="text/plain"/>
916
<StatusCode>401</StatusCode>
10-
<ReasonPhrase>Access Denied</ReasonPhrase>
17+
<ReasonPhrase>Unauthorized</ReasonPhrase>
18+
<Payload>
19+
{
20+
"issue": [
21+
{
22+
"code": "forbidden",
23+
"details": {
24+
"coding": [
25+
{
26+
"code": "ACCESS_DENIED",
27+
"display": "Missing or invalid OAuth 2.0 bearer token in request.",
28+
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
29+
"version": "1"
30+
}
31+
]
32+
},
33+
"diagnostics": "Invalid access token - Access Denied.",
34+
"severity": "error"
35+
}
36+
],
37+
"resourceType": "OperationOutcome"
38+
}
39+
</Payload>
1140
</Set>
1241
</FaultResponse>
1342
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
14-
</RaiseFault>
43+
</RaiseFault>

proxies/live/apiproxy/targets/target.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
</Request>
1717
</PreFlow>
1818
<FaultRules>
19+
<FaultRule name="unauthorized">
20+
<Step>
21+
<Name>RaiseFault.401Unauthorized</Name>
22+
<Condition>
23+
oauthV2.OauthV2.VerifyAccessToken.failed = true or fault.name = "invalid_access_token" or fault.name = "InvalidAccessToken" or fault.name = "access_token_not_approved" or fault.name = "apiresource_doesnot_exist" or fault.name = "InvalidAPICallAsNo" or fault.name = "ApiProductMatchFound"
24+
</Condition>
25+
</Step>
26+
</FaultRule>
1927
<FaultRule name="access_token_expired">
2028
<Step>
2129
<Name>ExtractVariables.OAuthErrorFaultString</Name>

0 commit comments

Comments
 (0)