Skip to content

Instantly share code, notes, and snippets.

@mattruma

mattruma/AllOperationsPolicy.xml Secret

Last active Jun 3, 2020
Embed
What would you like to do?
post-1505
<policies>
<inbound>
<base />
<validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid." require-scheme="Bearer" output-token-variable-name="jwt">
<openid-config url="https://ADB2C_TENANT_NAME.b2clogin.com/ADB2C_TENANT_NAME.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=B2C_1_SignUp_SignIn" />
<audiences>
<audience>API_AUDIENCE</audience>
</audiences>
<required-claims>
<claim name="scp" match="any" separator=" ">
<value>Users.ReadWrite</value>
<value>Organizations.ReadWrite</value>
</claim>
</required-claims>
</validate-jwt>
<set-variable name="userId" value="@(context.Request.Headers["Authorization"].First().Split(' ')[1].AsJwt()?.Claims["oid"].FirstOrDefault())" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
<policies>
<inbound>
<base />
<set-backend-service id="apim-generated-policy" backend-id="NAME_OF_AZURE_FUNCTION_APP" />
<set-body>@{
JObject body = context.Request.Body.As<JObject>();
body.Add(new JProperty("userId", ((string)context.Variables["userId"])));
return body.ToString();
}</set-body>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.