{
  "type": "oauth_provider",
  "api_version": "2.0.0",
  "name": "mtls-oauth",
  "title": "mtls-oauth",
  "debug": false,
  "provider_type": "native",
  "scopes": {
    "payment": "payment scope"
  },
  "grants": [
    "application"
  ],
  "gateway_version": "6000",
  "native_provider": {
    "clients": [
      "confidential"
    ],
    "authorize_path": "/oauth2/authorize",
    "token_path": "/oauth2/token",
    "pkce": {
      "enabled": true,
      "required": false,
      "allow_plain": false
    },
    "native_provider_5000": {
      "identity_extraction": {
        "type": "default_form"
      },
      "authorization": {
        "type": "authenticated"
      },
      "authentication": {},
      "scope_validators": {}
    },
    "advanced_scope_security": {
      "enabled": false,
      "mode": [
        "basic-auth"
      ],
      "basic_auth": {
        "request_headername": "x-advanced-scope-basic-authorization-header"
      }
    },
    "access_code_ttl": 300,
    "access_token_ttl": 3600,
    "access_token_one_time_use": false,
    "maximum_consent_ttl": 0,
    "refresh_token": {
      "enabled": false,
      "count": 2048,
      "ttl": 2682000,
      "one_time_use": true
    },
    "revocation": {
      "enabled": false,
      "type": "native",
      "resource_owner_revocation_path": "/oauth2/issued",
      "client_revocation_path": "/oauth2/revoke",
      "application_revocation": {
        "enabled": false
      },
      "owner_revocation": {
        "enabled": false
      },
      "third_party_fail_on_error": true
    },
    "token_introspection": {
      "enabled": false,
      "introspection_path": "/oauth2/introspect"
    },
    "token_metadata": {
      "enabled": true,
      "source": [
        "authentication_url"
      ],
      "header_name_payload": "X-API-OAUTH-METADATA-FOR-PAYLOAD",
      "header_name_token": "X-API-OAUTH-METADATA-FOR-ACCESSTOKEN"
    },
    "openid_connect": {
      "enabled": false
    },
    "api": {
      "info": {
        "description": "",
        "x-ibm-name": "mtls-oauthPROVIDER_ID",
        "version": "1.0.0",
        "title": "mtls-oauth"
      },
      "x-ibm-configuration": {
        "gateway": "datapower-api-gateway",
        "assembly": {
          "execute": [
            {
              "oauth": {
                "title": "validate-request",
                "version": "2.0.0",
                "description": "Validates the incoming OAuth request (scopes, client)",
                "oauth-provider-settings-ref": {
                  "default": "mtls-oauth"
                },
                "supported-oauth-components": [
                  "OAuthValidateRequest"
                ]
              }
            },
            {
              "switch": {
                "version": "2.0.0",
                "title": "oauth-auto-generated-switch",
                "case": [
                  {
                    "condition": "($operationPath() = '/oauth2/token')",
                    "execute": [
                      {
                        "oauth": {
                          "title": "verify-and-collect",
                          "version": "2.0.0",
                          "description": "Standard token path steps",
                          "oauth-provider-settings-ref": {
                            "default": "mtls-oauth"
                          },
                          "supported-oauth-components": [
                            "OAuthVerifyAZCode",
                            "OAuthVerifyRefreshToken",
                            "OAuthCollectMetadata"
                          ]
                        }
                      },
                      {
                        "gatewayscript": {
                          "version": "2.0.0",
                          "title": "bind-token-to-certificate",
                          "source": "// GatewayScript placed in the token path of the Native OAuth provider assembly,\n// right before the OAuthGenerateAccessToken policy.\n// RFC 8705 section 3.1: bind the access token to the client certificate.\n// APIC access tokens are opaque, so the binding is stored as token metadata (\"miscinfo\"):\n//   x5t#S256 : SHA-256 thumbprint of the DER certificate, base64url (the RFC 8705 \"cnf\" value)\n//   fp       : SHA-1 fingerprint in the same format as the context variable\n//              application.certificate.fingerprint, so that the protected API can compare\n//              without computing any hash.\nvar crypto = require('crypto');\n\nvar raw = context.get('request.headers.x-client-certificate');   // relayed by the TLS terminator\nvar b64 = String(raw || '')\n  .replace(/-----BEGIN CERTIFICATE-----|-----END CERTIFICATE-----/g, '')\n  .replace(/\\s+/g, '');\n\nif (!b64) {\n  context.reject('invalid_client', 'A client certificate is required to obtain a certificate-bound token');\n  context.message.statusCode = '401 Unauthorized';\n} else {\n  var der = Buffer.from(b64, 'base64');\n  var x5t = crypto.createHash('sha256').update(der).digest('base64')\n    .replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n  var fp = crypto.createHash('sha1').update(der).digest('hex').toUpperCase().replace(/(..)(?=.)/g, '$1:');\n  var binding = 'x5t#S256=' + x5t + ';fp=' + fp;\n  context.set('oauth.processing.metadata.access_token', binding);   // inside the token -> misc_info\n  context.set('oauth.processing.metadata.payload', binding);        // returned to the client as \"metadata\"\n}"
                        }
                      },
                      {
                        "oauth": {
                          "title": "generate-access-token",
                          "version": "2.0.0",
                          "description": "Issues the certificate-bound access token",
                          "oauth-provider-settings-ref": {
                            "default": "mtls-oauth"
                          },
                          "supported-oauth-components": [
                            "OAuthGenerateAccessToken"
                          ]
                        }
                      }
                    ]
                  },
                  {
                    "otherwise": [
                      {
                        "oauth": {
                          "title": "introspect-revoke",
                          "version": "2.0.0",
                          "description": "Introspection and revocation",
                          "oauth-provider-settings-ref": {
                            "default": "mtls-oauth"
                          },
                          "supported-oauth-components": [
                            "OAuthIntrospectToken",
                            "OAuthRevokeToken"
                          ]
                        }
                      }
                    ]
                  }
                ]
              }
            }
          ]
        },
        "type": "oauth",
        "testable": true,
        "enforced": true,
        "phase": "realized",
        "cors": {
          "enabled": true
        },
        "properties": {}
      },
      "basePath": "/mtls-oauth",
      "swagger": "2.0",
      "host": "$(catalog.host)",
      "schemes": [
        "https"
      ],
      "paths": {
        "/oauth2/token": {
          "post": {
            "consumes": [
              "application/x-www-form-urlencoded"
            ],
            "produces": [
              "application/json"
            ],
            "summary": "Endpoint for obtaining access token using Authorization code, Application and Password grants",
            "description": "This endpoint allows requesting an access token following one of the flows below:\n        - Access Code (exchange access code for an access token)\n        - Client Credentials (2-legged, resource owner credentials are not obtained)\n        - Resource Owner Password Credentials (2-legged, client provides resource owner name and password)\n        - Refresh Token (exchange refresh token for a new access token)",
            "parameters": [
              {
                "name": "grant_type",
                "in": "formData",
                "required": true,
                "type": "string",
                "enum": [
                  "authorization_code",
                  "password",
                  "client_credentials",
                  "refresh_token",
                  "urn:ietf:params:oauth:grant-type:jwt-bearer"
                ]
              },
              {
                "name": "client_id",
                "in": "formData",
                "description": "application requesting the token, if there is no Authorization header in the request, this parameter is required",
                "required": false,
                "type": "string"
              },
              {
                "name": "client_secret",
                "in": "formData",
                "description": "application requesting the token, if the provider is confidential, this parameter is required",
                "required": false,
                "type": "string"
              },
              {
                "name": "scope",
                "in": "formData",
                "description": "requested scope of this authorization",
                "required": false,
                "type": "string"
              },
              {
                "name": "code",
                "in": "formData",
                "description": "access code generated from the az get request, required in Access code flow",
                "required": false,
                "type": "string"
              },
              {
                "name": "refresh_token",
                "in": "formData",
                "description": "refresh token generated from the last token request, required in refresh token flow",
                "required": false,
                "type": "string"
              },
              {
                "name": "assertion",
                "in": "formData",
                "description": "id_token in the JWT request, required in JWT flow",
                "required": false,
                "type": "string"
              }
            ],
            "responses": {
              "200": {
                "description": "200 OK"
              }
            }
          }
        }
      },
      "definitions": {
        "access_token_response": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "access_token"
          ],
          "properties": {
            "access_token": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "user_registry_urls": [],
  "jwt_provider_urls": [],
  "tls_client_profile_urls": []
}
