Skip to content

Instantly share code, notes, and snippets.

@hatsunea
Created February 15, 2026 04:10
Show Gist options
  • Select an option

  • Save hatsunea/76c9a255ec08e1fcd67ca34d79a0455e to your computer and use it in GitHub Desktop.

Select an option

Save hatsunea/76c9a255ec08e1fcd67ca34d79a0455e to your computer and use it in GitHub Desktop.
<!--
- Policies are applied in the order they appear.
- Position <base/> inside a section to inherit policies from the outer scope.
- Comments within policies are not preserved.
-->
<!-- Add policies as children to the <inbound>, <outbound>, <backend>, and <on-error> elements -->
<policies>
<!-- Throttle, authorize, validate, cache, or transform the requests -->
<inbound>
<base />
<!-- パスを書き換えて /fujitsu/chat → /api/v1/action/defined/text:simple_chat/call -->
<rewrite-uri template="/api/v1/action/defined/text:simple_chat/call" />
<set-header name="Ocp-Apim-Subscription-Key" exists-action="delete" />
<cors>
<allowed-origins>
<origin>*</origin>
</allowed-origins>
<allowed-methods>
<method>*</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
</cors>
<set-backend-service base-url="https://{{tenant}}.generative-ai-platform.cloud.global.fujitsu.com" />
<!-- パスを書き換えて /fujitsu/chat → /api/v1/action/defined/text:simple_chat/call -->
<rewrite-uri template="/api/v1/action/defined/text:simple_chat/call" />
<send-request mode="new" response-variable-name="tokenResponse" timeout="20">
<set-url>https://{{tenant}}.b2clogin.com/tfp/{{tenant}}.onmicrosoft.com/{{policy}}/oauth2/v2.0/token</set-url>
<set-method>POST</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/x-www-form-urlencoded</value>
</set-header>
<set-body>@{
return "grant_type=client_credentials"
+ "&client_id={{client-id}}"
+ "&client_secret={{client-secret}}"
+ "&scope={{scope}}";
}</set-body>
</send-request>
<set-variable name="accessToken" value="@{
var json = ((IResponse)context.Variables["tokenResponse"]).Body.As<string>();
var obj = JObject.Parse(json);
return (string)obj["access_token"];
}" />
<set-header name="Authorization" exists-action="override">
<value>@($"Bearer {context.Variables["accessToken"]}")</value>
</set-header>
</inbound>
<!-- Control if and how the requests are forwarded to services -->
<backend>
<base />
</backend>
<!-- Customize the responses -->
<outbound>
<base />
</outbound>
<!-- Handle exceptions and customize error responses -->
<on-error>
<base />
</on-error>
</policies>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment