<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tom Van Oppens on Medium]]></title>
        <description><![CDATA[Stories by Tom Van Oppens on Medium]]></description>
        <link>https://medium.com/@tom_91498?source=rss-f265dcb1ae3d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YkAi7YO0Dg-BNB5G.jpg</url>
            <title>Stories by Tom Van Oppens on Medium</title>
            <link>https://medium.com/@tom_91498?source=rss-f265dcb1ae3d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:39:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tom_91498/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Client assertion grant type with IBM API Connect]]></title>
            <link>https://medium.com/@tom_91498/client-assertion-grant-type-with-ibm-api-connect-5aa50bfb3f46?source=rss-f265dcb1ae3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/5aa50bfb3f46</guid>
            <category><![CDATA[apiconnect]]></category>
            <category><![CDATA[oauth2]]></category>
            <dc:creator><![CDATA[Tom Van Oppens]]></dc:creator>
            <pubDate>Thu, 28 May 2020 15:53:55 GMT</pubDate>
            <atom:updated>2020-05-29T10:43:25.579Z</atom:updated>
            <content:encoded><![CDATA[<p>Since the overhaul of native OAuth2 providers that came in API Connect v2018 (the one prior to v10) the OAuth2 provider became super flexible.</p><p>In this post I’ll implement support for the client_assertion grant type with a JWT as per <a href="https://tools.ietf.org/html/rfc7523">https://tools.ietf.org/html/rfc7523</a>. An assertion is a different way of identifying you application, there quite some flexibility of what you put in the assertion.</p><p>Some advantages.<br>- As the provider I don’t have to keep the secret belonging to the client<br>- if the token request is intercepted it’s less problematic as it can has an expiration time</p><p>I have chosen to keep it simple an only put the minimum required claims in there<br>- iss: issuer (our clientid)<br>- sub: subject (our clientid)<br>- aud: audience (the endpoint for whom this assertion is intended (full URL))<br>- exp: time (expiry time of the assertion in epoch seconds)</p><p>Below an example ( you can decode it at https://jwt.io )</p><pre>eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIwMDE2NDc5MzBhNTQ1NjRkMTQ5Zjg1OGMwMzIzMTEwOCIsInN1YiI6IjAwMTY0NzkzMGE1NDU2NGQxNDlmODU4YzAzMjMxMTA4IiwiYXVkIjoibXlvYXV0aHByb3ZpZGVydXJsIiwiZXhwIjoxNTE2MjM5MDIyfQ.lH-JmlzzdTtNrchMfb3fyYYcuq_LqS73fsjkMOvvIvgmm-X1bmd-EDDvTS-gOZ-H6jQXtF9Tvxwt0Q8-3FVmGO7IQg71hLCwVPngTO3e2qOZK6SlxTzbmvHmdWNmlwbjz0EmbKYHXxP5nMwREKvAig9qtgvNafle5JZVfQX9ZWkBbSrzuOJXrOeMsOdS0sx5HZggFc2S4Tqd8WgpawqA7CfZk61tJLkEEQn031dAY913aJTeXWw9pMipfBWQFDr2fWAZEuxp9yzsE5XAhaNDOgc5K0tQpolAy5ThY88KC2nTH2AQTQlvlnPw_IxeepeiYtD7K3oeoVnZ-KzAil09zw</pre><p>So the request would look something like this.</p><pre>curl -X POST ‘<a href="https://gw1.cp4i-284824-1ea39f2197613090e80c4981ab6eab96-0000.eu-de.containers.appdomain.cloud/apic1/sandbox/oauth3/oauth2/token&#39;">https://mygatewat/apic1/sandbox/oauth3/oauth2/token&#39;</a> \<br>-H ‘Content-Type: application/x-www-form-urlencoded’ \<br> — data-urlencode ‘grant_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer’ \<br> — data-urlencode ‘scope=scope1’ \<br> — data-urlencode ‘assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIwMDE2NDc5MzBhNTQ1NjRkMTQ5Zjg1OGMwMzIzMTEwOCIsInN1YiI6IjAwMTY0NzkzMGE1NDU2NGQxNDlmODU4YzAzMjMxMTA4IiwiYXVkIjoibXlvYXV0aHByb3ZpZGVydXJsIiwiZXhwIjoxNTE2MjM5MDIyfQ.lH-JmlzzdTtNrchMfb3fyYYcuq_LqS73fsjkMOvvIvgmm-X1bmd-EDDvTS-gOZ-H6jQXtF9Tvxwt0Q8-3FVmGO7IQg71hLCwVPngTO3e2qOZK6SlxTzbmvHmdWNmlwbjz0EmbKYHXxP5nMwREKvAig9qtgvNafle5JZVfQX9ZWkBbSrzuOJXrOeMsOdS0sx5HZggFc2S4Tqd8WgpawqA7CfZk61tJLkEEQn031dAY913aJTeXWw9pMipfBWQFDr2fWAZEuxp9yzsE5XAhaNDOgc5K0tQpolAy5ThY88KC2nTH2AQTQlvlnPw_IxeepeiYtD7K3oeoVnZ-KzAil09zw’</pre><p>What will happen in the OAuth provider is that rather than validating the client secret the provider will validate the assertion against the public key of the application (to keep it simple I have hard-coded the public JWK of the application in the verification code, normally you would take this specific to the client somewhere, but that’s outside the scope of this article)</p><p>Of-course the provider you find below isn’t fit for production use (I didn’t put in any error handling, optimizations or checked for vulnerabilities)</p><p>If you want help to achieve something like this and need some help, reach out to me or one of my colleagues at the IBM Cloud Integration Expert Labs</p><p>API Connect Native OAuth assembly with support for the assertion grant type<br>(below you will find the corresponding crypto material for the JWK used to validate the assertion (don’t worry , it’s throwaway crypto))</p><p>Alternatively you can use the wizard and select Resource owner — JWT in the grant types, this will generate a different assembly. The idea here is to show of the flexibility you have.</p><pre>info:<br>  description: &#39;&#39;<br>  x-ibm-name: oauth2caf93f5c-bfd1-45f4-945a-dab73273ee96<br>  version: 1.0.0<br>  title: OAuth2<br>x-ibm-configuration:<br>  gateway: datapower-api-gateway<br>  assembly:<br>    execute:<br>      - switch:<br>          version: 2.0.0<br>          title: switch<br>          case:<br>            - condition: ($operationPath() = &#39;/oauth2/token&#39;)<br>              execute:<br>                - gatewayscript:<br>                    version: 2.0.0<br>                    title: check if request is assertion<br>                    source: |<br>                      const apim = require(&quot;apim&quot;);<br>                      /* the context variable app is empty, in order to <br>                      access this information we call an api that<br>                      returns the metadata for the application<br>                      */<br>                      apim.readInputAsBuffer(function (err, buffer) {<br>                        if (buffer) {<br>                          const requestString = buffer.toString(&quot;utf8&quot;);<br>                          console.error(requestString);<br>                          if (<br>                            requestString.includes(<br>                              &quot;grant_type=urn%3Aietf%3Aparams%3Aoauth%3Aclient-assertion-type%3Ajwt-bearer&quot;<br>                            )<br>                          ) {<br>                            context.set(&quot;assertion&quot;, true);<br>                            console.error(&quot;set to true&quot;);<br>                          } else {<br>                            context.set(&quot;assertion&quot;, false);<br>                            console.error(&quot;set to false&quot;);<br>                          }<br>                        }<br>                      });<br>                - switch:<br>                    version: 2.0.0<br>                    title: switch<br>                    case:<br>                      - condition: (assertion = false)<br>                        execute:<br>                          - oauth:<br>                              title: oauth-auto-generated-1<br>                              version: 2.0.0<br>                              description: &gt;-<br>                                This oauth policy performs all OAuth/OpenID<br>                                Connect protocol steps that are needed for OAuth<br>                                Validation by default. The inputs and outputs of<br>                                each of the steps are driven by documented<br>                                context variables. Add or remove the Supported<br>                                OAuth Components as required.<br>                              oauth-provider-settings-ref:<br>                                default: OAuth2<br>                              supported-oauth-components:<br>                                - OAuthValidateRequest<br>                          - oauth:<br>                              title: oauth-auto-generated-3<br>                              version: 2.0.0<br>                              description: &gt;-<br>                                This oauth policy performs all OAuth/OpenID<br>                                Connect protocol steps that are needed for token<br>                                path by default. The inputs and outputs of each<br>                                of the steps are driven by documented context<br>                                variables. Add or remove the Supported OAuth<br>                                Components as required.<br>                              oauth-provider-settings-ref:<br>                                default: OAuth2<br>                              supported-oauth-components:<br>                                - OAuthGenerateAccessToken<br>                                - OAuthCollectMetadata<br>                      - condition: (assertion = true)<br>                        execute:<br>                          - gatewayscript:<br>                              version: 2.0.0<br>                              title: &gt;-<br>                                handle assertion and set variables to generate<br>                                token<br>                              source: &gt;<br>                                const apim = require(&quot;apim&quot;);</pre><pre>const qs = require(&quot;querystring&quot;);</pre><pre>const jwt = require(&quot;jwt&quot;);</pre><pre>//this is the static object representing  the<br>                                public key of the client</pre><pre>const jwkString =<br>                                  &#39; { &quot;kty&quot;: &quot;RSA&quot;, &quot;kid&quot;: &quot;signincertforassetion&quot;,   &quot;x5t&quot;: &quot;pFYNC0f5U1K0oMOhtj-IOKf9bFA&quot;,   &quot;n&quot;: &quot;rCh0FvgOTdgc356MZ7Zncf5udv4RE2OHRNBH-GL6RHnmBryip3RukTm3ZCn516uup_LFWeLJU7-iAGg6zyj_5WH3ICl_HIGiKt07zwkeCKIN1lonwC78Rbl1S9B4w5gnzoAdN_cVBs-IEBQP7xuUOKFx5dXl13XdvUQHqUC5q-0lieZuiQrGj475lvj9fjOTQ3FH5hmaEl30BEgjAunWW41-dqbsuzoeudRnMLYhmMbKDooDE0QBsJr0kGSXq_FOEFTr4fPRmtoaHaijgzqLouSu8QiCnvbsh6WGDTepzvsmgIHydSuvB0jlBq9pHyy4vlSWEi9aBdrTfIovsoY8Yw&quot;,   &quot;e&quot;: &quot;AQAB&quot;        }&#39;;</pre><pre>const jwk = JSON.parse(jwkString);</pre><pre>apim.readInputAsBuffer(function (err, buffer) {<br>                                  if (buffer) {<br>                                    const requestString = buffer.toString(&quot;utf8&quot;);<br>                                    const request = qs.parse(requestString);<br>                                    const decoder = new jwt.Decoder(request.assertion);<br>                                    decoder.addOperation(&quot;verify&quot;, jwk);<br>                                    decoder.decode((decodeError, decoded) =&gt; {<br>                                      if (decodeError) {<br>                                        console.error(<br>                                          `An error occured while validating the request signature: ${decodeError}`<br>                                        );<br>                                      } else {<br>                                        // see that the token is intended for us<br>                                        const api = apim.getvariable(&quot;api&quot;);<br>                                        //check if the audience matches<br>                                        console.error(&quot;decoded.aud&quot;, decoded.aud);<br>                                        console.error(<br>                                          &quot;expected aud&quot;,<br>                                          `<a href="https://${api.endpoint.hostname}/$%7Bapi.org.name%7D/$%7Bapi.catalog.path%7D/$%7Bapi.root%7D$%7Bapi.operation.path%7D%60">https://${api.endpoint.hostname}/${api.org.name}/${api.catalog.path}/${api.root}${api.operation.path}`</a><br>                                        );<br>                                        if (<br>                                          decoded.aud ===<br>                                          `<a href="https://${api.endpoint.hostname}/$%7Bapi.org.name%7D/$%7Bapi.catalog.path%7D/$%7Bapi.root%7D$%7Bapi.operation.path%7D%60">https://${api.endpoint.hostname}/${api.org.name}/${api.catalog.path}/${api.root}${api.operation.path}`</a><br>                                        ) {<br>                                          //check expiry<br>                                          if (new Date(decoded.exp * 1000) &gt;= new Date()) {<br>                                            // set the variables to generate the token<br>                                            const oauth = {<br>                                              client_id: decoded.sub,<br>                                              //dummy grant type that doesn&#39;t require the secret<br>                                              grant_type: &quot;authorization_code&quot;,<br>                                              //we use this information to drive the clientid and other data int o the token<br>                                              verified_code: {<br>                                                client_id: decoded.sub,<br>                                                resource_owner: decoded.sub,<br>                                                scope: request.scope,<br>                                                is_verified: true,<br>                                              },<br>                                            };<br>                                            apim.setvariable(&quot;oauth.processing&quot;, oauth);<br>                                          }else {<br>                                            console.error(&#39;assertion expired&#39;)<br>                                          }<br>                                        }<br>                                      }<br>                                    });<br>                                  }<br>                                });<br>                          - oauth:<br>                              title: oauth-auto-generated-3<br>                              version: 2.0.0<br>                              description: &gt;-<br>                                This oauth policy performs all OAuth/OpenID<br>                                Connect protocol steps that are needed for token<br>                                path by default. The inputs and outputs of each<br>                                of the steps are driven by documented context<br>                                variables. Add or remove the Supported OAuth<br>                                Components as required.<br>                              oauth-provider-settings-ref:<br>                                default: OAuth2<br>                              supported-oauth-components:<br>                                - OAuthGenerateAccessToken<br>                                - OAuthCollectMetadata<br>                          - gatewayscript:<br>                              version: 2.0.0<br>                              title: strip refresh token<br>                              description: &gt;-<br>                                we use a grant type that wouldn&#39;t generate a<br>                                refresh token, but because of our workarounds it<br>                                does<br>                              source: |-<br>                                const apim = require(&quot;apim&quot;);<br>                                let token = apim.getvariable(&quot;message.body&quot;);<br>                                delete token.refresh_token;<br>                                delete token.refresh_token_expires_in;<br>                                delete token.refresh_token_count;<br>                                apim.setvariable(&quot;message.body&quot;, token);<br>          <br>            - otherwise:<br>                - oauth:<br>                    title: oauth-auto-generated-1<br>                    version: 2.0.0<br>                    description: &gt;-<br>                      This oauth policy performs all OAuth/OpenID Connect<br>                      protocol steps that are needed for OAuth Validation by<br>                      default. The inputs and outputs of each of the steps are<br>                      driven by documented context variables. Add or remove the<br>                      Supported OAuth Components as required.<br>                    oauth-provider-settings-ref:<br>                      default: OAuth2<br>                    supported-oauth-components:<br>                      - OAuthValidateRequest<br>                - switch:<br>                    version: 2.0.0<br>                    title: oauth-auto-generated-switch<br>                    case:<br>                      - condition: ($operationPath() = &#39;/oauth2/authorize&#39;)<br>                        execute:<br>                          - user-security:<br>                              title: user-security-auto-generated<br>                              version: 2.1.0<br>                              description: &gt;-<br>                                This user security policy performs EI(basic) and<br>                                AU(auth url) check for oauth assembly. Change<br>                                the security check method as required<br>                              factor-id: default<br>                              extract-identity-method: redirect<br>                              ei-stop-on-error: true<br>                              user-auth-method: user-registry<br>                              au-stop-on-error: true<br>                              user-az-method: authenticated<br>                              az-stop-on-error: true<br>                              redirect-url: &#39;<a href="https://example.com&/#39;">https://example.com&#39;</a><br>                              redirect-time-limit: 300<br>                              user-registry: userandpasslettera<br>                              auth-response-headers-pattern: (?i)x-api*<br>                              auth-response-header-credential: X-API-Authenticated-Credential<br>                          - oauth:<br>                              title: oauth-auto-generated-2<br>                              version: 2.0.0<br>                              description: &gt;-<br>                                This oauth policy performs all OAuth/OpenID<br>                                Connect protocol steps that are needed for az<br>                                code path by default. The inputs and outputs of<br>                                each of the steps are driven by documented<br>                                context variables. Add or remove the Supported<br>                                OAuth Components as required.<br>                              oauth-provider-settings-ref:<br>                                default: oauth2<br>                              supported-oauth-components:<br>                                - OAuthGenerateAZCode<br>                                - OAuthGenerateAccessToken<br>                                - OAuthVerifyAZCode<br>                                - OAuthCollectMetadata<br>                      - otherwise:<br>                          - oauth:<br>                              title: oauth-auto-generated-4<br>                              version: 2.0.0<br>                              description: &gt;-<br>                                This oauth policy performs all OAuth/OpenID<br>                                Connect protocol steps that are needed for all<br>                                other paths by default. The inputs and outputs<br>                                of each of the steps are driven by documented<br>                                context variables. Add or remove the Supported<br>                                OAuth Components as required.<br>                              oauth-provider-settings-ref:<br>                                default: OAuth2<br>                              supported-oauth-components:<br>                                - OAuthIntrospectToken<br>                                - OAuthRevokeToken<br>    catch: []<br>  type: oauth<br>  testable: true<br>  enforced: true<br>  phase: realized<br>  cors:<br>    enabled: true<br>  properties: {}<br>swagger: &#39;2.0&#39;<br>host: $(catalog.host)<br>schemes:<br>  - https<br>basePath: /oauth3<br>paths:<br>  /oauth2/authorize:<br>    get:<br>      produces:<br>        - text/html<br>      summary: Endpoint for Authorization Code and Implicit grants<br>      description: &gt;-<br>        This endpoint allows an access token (Implicit) or access code<br>        (Authorization Code) request with the following parameters:<br>                      - Implicit (response_type = token, client_id, scope, redirect_uri(*), state(*))<br>                      - Authorization Code (response_type = code, client_id, scope, redirect_uri(*), state(*))<br>      parameters:<br>        - name: response_type<br>          in: query<br>          description: request an authorization code or an access token (implicit)<br>          required: false<br>          type: string<br>          enum:<br>            - code<br>            - token<br>        - name: client_id<br>          in: query<br>          description: client_id of the application which product is subscribed to<br>          required: false<br>          type: string<br>        - name: scope<br>          in: query<br>          description: Scope being requested<br>          type: string<br>          required: false<br>        - name: redirect_uri<br>          in: query<br>          type: string<br>          description: URI where user is redirected to after authorization<br>          required: false<br>        - name: state<br>          in: query<br>          type: string<br>          description: &gt;-<br>            This string will be echoed back to application when user is<br>            redirected<br>          required: false<br>      responses:<br>        &#39;200&#39;:<br>          description: An HTML form for authentication or authorization of this request.<br>        &#39;302&#39;:<br>          description: &gt;<br>            Redirect to the clients redirect_uri containing one of the following</pre><pre>- **authorization code** for Authorization code grant</pre><pre>- **access token** for Implicit grant</pre><pre>- **error** in case of errors, such as the user has denied the<br>            request<br>    post:<br>      consumes:<br>        - application/x-www-form-urlencoded<br>      produces:<br>        - text/html<br>      summary: Endpoint for Authorization Code and Implicit grants<br>      description: Submit approval to access token.<br>      security: []<br>      parameters:<br>        - name: response_type<br>          in: formData<br>          description: request an authorization code or an access token (implicit)<br>          required: false<br>          type: string<br>          enum:<br>            - code<br>            - token<br>        - name: client_id<br>          in: formData<br>          description: application requesting the access code or token<br>          required: false<br>          type: string<br>        - name: scope<br>          in: formData<br>          description: requested scope of this authorization<br>          required: false<br>          type: string<br>        - name: redirect_uri<br>          in: formData<br>          description: &gt;-<br>            URI the application is requesting this code or token to be<br>            redirected to<br>          required: false<br>          type: string<br>      responses:<br>        &#39;200&#39;:<br>          description: 200 OK<br>  /oauth2/token:<br>    post:<br>      consumes:<br>        - application/x-www-form-urlencoded<br>      produces:<br>        - application/json<br>      summary: &gt;-<br>        Endpoint for obtaining access token using Authorization code,<br>        Application and Password grants<br>      description: &gt;-<br>        This endpoint allows requesting an access token following one of the<br>        flows below:<br>                - Access Code (exchange access code for an access token)<br>                - Client Credentials (2-legged, resource owner credentials are not obtained)<br>                - Resource Owner Password Credentials (2-legged, client provides resource owner name and password)<br>                - Refresh Token (exchange refresh token for a new access token)<br>      parameters:<br>        - name: grant_type<br>          in: formData<br>          required: true<br>          type: string<br>          enum:<br>            - authorization_code<br>            - password<br>            - client_credentials<br>            - refresh_token<br>      responses:<br>        &#39;200&#39;:<br>          description: 200 OK<br>definitions:<br>  access_token_response:<br>    type: object<br>    additionalProperties: false<br>    required:<br>      - access_token<br>    properties:<br>      access_token:<br>        type: string<br>securityDefinitions: {}</pre><pre>-----BEGIN CERTIFICATE-----<br>MIICvDCCAaSgAwIBAgIEXs6uGDANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVz<br>aWduaW5jZXJ0Zm9yYXNzZXRp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y4iL0W0DQKgN3anfaSZezoMiS+yS+6FiW2My90x0QobXOaHLf<br>4tPkzCEtINSquwg5SwVsjQKBgQCddaExd7rIPjM5moSFkb9wQkVsZaH2WwZb1EDD<br>K17UfjoiD8rg5A7ejLZoL80iAX39UZBH5rYDslNYI+wxlGU+Uz5nIhwJ4qDfjgAb<br>z+fn+shbAp9MlyCZ0UWB6Rj1/vrooSN0uGHdel7mewgFz9oEFJ5cSJc7as6SmIjW<br>uQGeIQKBgBIZDxCLajJOdAdJ/kD58lAz7wrJgSxoy7jf6CT89GAfr3ehqSINEvbP<br>39MJ9NRktEPYPD1tB8on4KBeuUSFf5x4b1e7UTU0jJdlPonjkH0uDKhPirWK79+p<br>gp/8FkBiTtOmQ2Jii/WF5lucfKrQVuhaFu4o94kr3TdRlh/aX2hu<br>-----END RSA PRIVATE KEY-----</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5aa50bfb3f46" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic Registration with IBM API Connect]]></title>
            <link>https://medium.com/@tom_91498/dynamic-registration-with-ibm-api-connect-27f46f721011?source=rss-f265dcb1ae3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/27f46f721011</guid>
            <category><![CDATA[apiconnect]]></category>
            <category><![CDATA[oauth2]]></category>
            <dc:creator><![CDATA[Tom Van Oppens]]></dc:creator>
            <pubDate>Mon, 25 May 2020 16:30:15 GMT</pubDate>
            <atom:updated>2020-06-18T19:41:56.511Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dynamic Client Registration with IBM API Connect</h3><p>Lately some people have been asking me how to deliver <a href="https://tools.ietf.org/html/rfc7591">OAuth Dynamic registration</a> (rfc 7591)with API Connect.</p><p>The question you might ask yourself is, why isn’t dynamic registration support out of the box. The answer is quite simple, dynamic registration is a very “wide” specification your request could be a simple JSON (as in the example below) or you require a a JWKS provided to you over a mutual TLS.</p><p>Below a pratical guide with a very simple form of dynamic registration</p><p>First we need to create an application that</p><pre>./apic login — server MANAGERAPIENDPOINT — realm admin/default-idp-1</pre><p>Now that we are logged in we need to create a consumer application</p><pre>./apic registrations:create — format json — server MANAGERAPIENDPOINT app2.json</pre><p>Where app2.json would something like this</p><pre>{<br> “name”: “app2”,<br> “client_id”: “app2id”,<br> “client_secret”: “app2secret”,<br> “client_type”: “consumer_toolkit”<br>} </pre><p>(Important to note is the client type)</p><p>This application can now be used to call the consumer APIs and obtain tokens in name of a developer.</p><p>Attached below very simple dynamic registration API, The API will create a consumer application for a shared consumer organisation (ofcourse we can include dynamic creation of consumer organisation based on the request, ….). and then drives the client name and OAuth redirect information. This is very likely far too simple for most real world sceanrios as you wouldn’t want anyone just to be able to create a client. But it can serve a baseline to work from , or just as an inspiration.</p><p>Logically it performs the following<br>- check incoming request<br>- prepare OAuth token request <br>- obtain OAuth token to call consumer API<br>- prepare consumer API call to create application<br>- call API Connect consumer API <br>- create dynamic registration compliant response.</p><p>I also added a little legacy property that might be used for something specific to your implementation.</p><pre>swagger: &#39;2.0&#39;<br>info:<br>  title: DynamicRegistration<br>  x-ibm-name: dynamicregistration<br>  version: 1.0.0<br>schemes:<br>  - https<br>basePath: /dynamicregistration<br>securityDefinitions:<br>  clientIdHeader:<br>    type: apiKey<br>    in: header<br>    name: X-IBM-Client-Id<br>x-ibm-configuration:<br>  cors:<br>    enabled: true<br>  gateway: datapower-api-gateway<br>  type: rest<br>  phase: realized<br>  enforced: true<br>  testable: true<br>  assembly:<br>    execute:<br>      - parse:<br>          version: 2.0.0<br>          title: parse<br>          parse-settings-reference:<br>            default: apic-default-parsesettings<br>          output: parsed<br>          input: message<br>      - validate:<br>          version: 2.0.0<br>          title: validate<br>          input: parsed<br>          validate-against: definition<br>          output: validated<br>          definition: &#39;#/definitions/registrationRequest&#39;<br>      - gatewayscript:<br>          version: 2.0.0<br>          title: prepare Token Call<br>          description: prepare the token call<br>          source: &gt;-<br>            const apim = require(&#39;apim&#39;)</pre><pre>const username = apim.getvariable(&#39;api.properties.tokenUsername&#39;)</pre><pre>const password = apim.getvariable(&#39;api.properties.tokenPassword&#39;)</pre><pre>const client_id =<br>            apim.getvariable(&#39;api.properties.consumerAppClientId&#39;)</pre><pre>const client_secret =<br>            apim.getvariable(&#39;api.properties.consumerAppClientSecret&#39;)</pre><pre>const tokenBody =</pre><pre>{<br>                &quot;username&quot;: username,<br>                &quot;password&quot;: password,<br>                &quot;realm&quot;: &quot;consumer:apic1:sandbox/sandbox-idp&quot;,<br>                &quot;client_id&quot;: client_id,<br>                &quot;client_secret&quot;: client_secret,<br>                &quot;grant_type&quot;: &quot;password&quot;<br>            }</pre><pre>apim.setvariable(&#39;message.body&#39;,tokenBody)</pre><pre>apim.setvariable(&#39;message.headers.X-IBM-Consumer-Context&#39;,&#39;apic1.sandbox&#39;)</pre><pre>apim.setvariable(&#39;message.headers.Accept&#39;,&#39;application/json&#39;)</pre><pre>apim.setvariable(&#39;message.headers.Content-Type&#39;,&#39;application/json&#39;) <br>      - invoke:<br>          title: get token<br>          version: 2.0.0<br>          verb: POST<br>          target-url: $(api.properties.consumerapiEndpoint)/consumer-api/token<br>          follow-redirects: false<br>          timeout: 60<br>          parameter-control:<br>            type: blacklist<br>          header-control:<br>            type: blacklist<br>            values:<br>              - ^X-IBM-Client-Id$<br>          inject-proxy-headers: true<br>          cache-response: time-to-live<br>          cache-key: &#39;&#39;<br>          description: &#39;&#39;<br>          output: tokenResponse<br>          cache-ttl: 28800<br>      - gatewayscript:<br>          version: 2.0.0<br>          title: prepare app creation call<br>          description: check request and prepare the token call<br>          source: &gt;<br>            const apim = require(&quot;apim&quot;);</pre><pre>// Get variables from request</pre><pre>const validated = apim.getvariable(&quot;validated.body&quot;);</pre><pre>if(validated.client_name &amp;&amp; validated.redirect_uris &amp;&amp;<br>            validated.custom_property){<br>                const body = {<br>                    type: &quot;app&quot;,<br>                    api_version: &quot;2.0.0&quot;,<br>                    title: validated.client_name,<br>                    summary: &quot;little default application that we use for nothing&quot;,<br>                    state: &quot;enabled&quot;,<br>                    lifecycle_state: &quot;production&quot;,<br>                    redirect_endpoints: validated.redirect_uris,<br>                    metadata: {<br>                      legacy_property: validated.custom_property,<br>                    },<br>                  };<br>                  apim.setvariable(&quot;message.body&quot;, body);<br>                  apim.setvariable(<br>                    &quot;message.headers.Authorization&quot;,<br>                    `Bearer ${apim.getvariable(&quot;tokenResponse.body&quot;).access_token}`<br>                  );<br>                  apim.setvariable(&quot;message.headers.X-IBM-Consumer-Context&quot;, &quot;apic1.sandbox&quot;);<br>                  apim.setvariable(&quot;message.headers.Accept&quot;, &quot;application/json&quot;);<br>                  apim.setvariable(&quot;message.headers.Content-Type&quot;, &quot;application/json&quot;);<br>            }else {</pre><pre>apim.error(&quot;missingProperty&quot;);</pre><pre>}</pre><pre>//[&quot;<a href="https://example.com/redirect">https://example.com/redirect</a>&quot;,&quot;<a href="https://example.com/redirect2">https://example.com/redirect2</a>&quot;]<br>      - invoke:<br>          title: create application call<br>          version: 2.0.0<br>          verb: POST<br>          target-url: $(api.properties.consumerapiEndpoint)/consumer-api/orgs/tvo/apps<br>          follow-redirects: false<br>          timeout: 60<br>          parameter-control:<br>            type: blacklist<br>          header-control:<br>            type: blacklist<br>            values:<br>              - ^X-IBM-Client-Id$<br>          inject-proxy-headers: true<br>          cache-response: time-to-live<br>          cache-ttl: 28800<br>          cache-key: &#39;&#39;<br>          description: &#39;&#39;<br>          output: appResponse<br>      - gatewayscript:<br>          version: 2.0.0<br>          title: prepare response<br>          source: &gt;<br>            const apim = require(&quot;apim&quot;);</pre><pre>// Get variables from request</pre><pre>const appResponse = apim.getvariable(&quot;appResponse.body&quot;);</pre><pre>const body = {<br>              client_name: appResponse.title,<br>              client_id: appResponse.client_id,<br>              client_secret: appResponse.client_secret,<br>              redirect_uris: appResponse.redirect_endpoints,<br>              custom_property: appResponse.metadata.legacy_property,<br>            };</pre><pre>apim.setvariable(&quot;message.body&quot;, body);</pre><pre>apim.setvariable(&quot;message.headers.Content-Type&quot;,<br>            &quot;application/json&quot;);<br>    catch:<br>      - errors:<br>          - missingProperty<br>        execute:<br>          - gatewayscript:<br>              version: 2.0.0<br>              title: missing properties error<br>              source: |2-<br>                    const apim = require(&quot;apim&quot;);<br>                    const errorBody = {<br>                        httpCode : 422,<br>                        httpMessage : &quot;missing required property&quot;<br>                    } <br>                    apim.setvariable(&quot;message.status.code&quot;, 422);<br>                    apim.setvariable(&quot;message.body&quot;, errorBody);<br>  properties:<br>    consumerapiEndpoint:<br>      value: &gt;-<br>        <a href="https://consumer.cp4i-284824-1ea39f2197613090e80c4981ab6eab96-0000.eu-de.containers.appdomain.cloud/">https://CONSUMERAPIENDPOINT</a><br>      description: The URL of the target service<br>    tokenUsername:<br>      value: <a href="/service/mailto:tom.van.oppens@be.ibm.com">CONSUMERORGPORTALUSER</a><br>    tokenPassword:<br>      value: <a href="/service/mailto:tom.van.oppens@be.ibm.com">CONSUMERORGPORTALUSER</a><br>    consumerAppClientId:<br>      value: app2id<br>    consumerAppClientSecret:<br>      value: app2secret<br>  catalogs: {}<br>  application-authentication:<br>    certificate: false<br>definitions:<br>  registrationRequest:<br>    type: object<br>    additionalProperties: false<br>    properties:<br>      client_name:<br>        type: string<br>        example: testapp<br>      custom_property:<br>        type: string<br>        example: legacy1<br>      redirect_uris:<br>        type: array<br>paths:<br>  /:<br>    post:<br>      responses:<br>        &#39;200&#39;:<br>          description: success<br>          schema:<br>            type: string<br>      parameters:<br>        - name: requestBody<br>          in: body<br>          required: true<br>          schema:<br>            $ref: &#39;#/definitions/registrationRequest&#39;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27f46f721011" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>