<?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 Wayne Blacklock on Medium]]></title>
        <description><![CDATA[Stories by Wayne Blacklock on Medium]]></description>
        <link>https://medium.com/@wayne.blacklock?source=rss-8cb90ec18819------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*uh65VktprJVQ5HtN</url>
            <title>Stories by Wayne Blacklock on Medium</title>
            <link>https://medium.com/@wayne.blacklock?source=rss-8cb90ec18819------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 06:04:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wayne.blacklock/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[Integrating ForgeRock & Apigee]]></title>
            <link>https://medium.com/@wayne.blacklock/integrating-forgerock-apigee-322e315c89e4?source=rss-8cb90ec18819------2</link>
            <guid isPermaLink="false">https://medium.com/p/322e315c89e4</guid>
            <category><![CDATA[integration]]></category>
            <category><![CDATA[oauth]]></category>
            <category><![CDATA[forgerock]]></category>
            <category><![CDATA[apigee]]></category>
            <category><![CDATA[identity]]></category>
            <dc:creator><![CDATA[Wayne Blacklock]]></dc:creator>
            <pubDate>Sun, 16 Dec 2018 14:36:19 GMT</pubDate>
            <atom:updated>2023-10-20T09:17:16.342Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*Dm1hQFJgSUCNUbcpMzbgOA.png" /></figure><p>We are often asked how ForgeRock can be integrated with a customers existing API gateway. This is a common security pattern, especially with OAuth 2.0 based approaches. Today I’m going to look at how to do this with Apigee, following Apigee’s advice on how to integrate with a third party authorization server.</p><ol><li><a href="#77c5">Prerequisites</a></li><li><a href="#2365">Proxying the API with Apigee</a></li><li><a href="#d263">Retrieving an OAuth 2.0 Access Token</a></li><li><a href="#92e7">Protecting the API with OAuth 2.0</a></li></ol><p><em>Note: Things have moved on in the time since I have written this blog and we have been working directly with Apigee to determine best practice for integration. We have published this here:</em></p><p><a href="https://community.forgerock.com/t/common-am-apigee-integration-patterns/1169">https://community.forgerock.com/t/common-am-apigee-integration-patterns/1169</a></p><p><em>Leaving this blog up in case it’s useful for anyone!</em></p><h3>Prerequisites</h3><ul><li>A ForgeRock AM (Open AM) instance hosted somewhere that is accessible to Apigee.</li><li>An Apigee account (you can freely sign up for one!).</li><li>An HTTP based API to protect.</li><li>Postman/cURL</li></ul><p>Let’s get started.</p><h3>Proxying the API with Apigee</h3><p>The very first thing we need to do is create an API proxy in Apigee, this proxy will flow any requests through to our API, applying whatever behaviour we have configured in the gateway.</p><p>Select <strong>API Proxies</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*lJK2a5iT61cu-n8uazcmUw.png" /></figure><p>Then <strong>+Proxy</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*685CgvTwx4R7HmmUxgJSqg.png" /></figure><p>Select <strong>Reverse Proxy </strong>and hit <strong>Next</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8oQonCyF2fbSUdkBL6H2w.png" /></figure><p><em>Note: You can use an OpenAPI definition if you have set up or imported one previously. I’m going to skip that here but if you do have one already it’ll save you some time when you come to defining the requests in the next steps.</em></p><p>Enter your proxy details, you need to define a <strong>Proxy Base Path </strong>which is the path Apigee will create that will direct requests to your API, you need to tell Apigee where the<strong> Existing API</strong> can be found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3a4dP2cLphaHdgyU3GEc9A.png" /></figure><p>We’re going to start with <strong>Pass through</strong> i.e. no authorisation is performed and the request flows through through the API directly. This allows us to validate some basic connectivity before getting into our ForgeRock configuration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-WVjM6Ph0b5LeizQNDhLzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BFsJdSOouTNd-S-XZylvlQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ndv32nWbEkhiywBWkdFhVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wBuIc3lc9g3t1piEgAmOqA.png" /></figure><p>Follow the link to <strong>View forgerock proxy in the editor</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NdVLlj_VLpyi1AxZxNqJ_w.png" /></figure><p>Before going any further we should be able to test that Apigee is proxying correctly to our API. Try hitting the Proxy Endpoint. You should see exactly the same result as if you hit your API directly.</p><pre>curl -X GET <a href="http://wayneblacklock-test.apigee.net/forgerock/api/wblacklock">http://wayneblacklock-test.apigee.net/forgerock/bank/api/wblacklock</a></pre><pre>{&quot;_id&quot;:&quot;wblacklock&quot;,&quot;_rev&quot;:&quot;5&quot;,&quot;frdpmfapref&quot;:&quot;push&quot;,&quot;resourceSet&quot;…</pre><p>Now we know Apigee is proxying correctly we can start doing something interesting with it.</p><h3>Retrieving an OAuth 2.0 Access Token</h3><p>We need to complete several configuration steps.</p><p><strong><em>Setup OAuth2 Provider Service</em></strong></p><p>Log into AM as administrator, navigate to <strong>Top Level Realm (</strong>or the realm you wish to use).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aPiZ9IjCpkydPprrfwJoPw.png" /></figure><p><strong>Services</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F045b141EIgcgpncGAMjTg.png" /></figure><p><strong>Add a Service</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*tmZcA4dwyYyCN-gSAadrgA.png" /></figure><p>Select <strong>OAuth 2 Provider</strong> and set some <strong>scopes</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8XQ5oCcrcvkIdzdMEx8xcw.png" /></figure><p>We now have an <strong>OAuth2 Provider </strong>service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-nvADa7cU99H8PyaE2pgsQ.png" /></figure><p>Lets turn on <strong>Stateless</strong> access tokens as most organisations seem to be favouring their use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*g-PbAbqtV957Fpv09SNSrA.png" /></figure><p><strong>Save Changes</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*UKqF42vxj3jg1YW8O88Afw.png" /></figure><p><strong><em>Create OAuth2 Client Application</em></strong></p><p>Before we can request an <strong>access token</strong> we need an <strong>OAuth2 </strong>client application.</p><p>Navigate to <strong>Applications</strong>, <strong>OAuth 2.0</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*--HAGKdR1Qy11R2C6CJMHA.png" /></figure><p><strong>Add Client</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*2_zYq9tLAot8XrsHpevsMA.png" /></figure><p>Enter a <strong>Client ID </strong>and <strong>Client secret</strong> of your choosing, and the scopes you defined earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N-XrPEQMqBrAW7X6Z7HolA.png" /></figure><p>Then <strong>Create</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/166/1*ZKEvHh_Br9yBljgDMyaxNw.png" /></figure><p>We have everything we need now to request an <strong>access token</strong>. We are going to use the simple <strong>Password Grant</strong> type for the rest of this exercise although note that all OAuth grant types are supported by ForgeRock AM.</p><pre>curl -X POST \<br>  <a href="http://authtree.openrock.org:8080/openam/oauth2/realms/root/access_token">http://authtree.openrock.org:8080/openam/oauth2/realms/root/access_token</a> \<br>  -H &#39;Content-Type: application/x-www-form-urlencoded&#39; \<br>  -d &#39;grant_type=password&amp;username=demo&amp;password=changeit&amp;scope=read&amp;client_id=example&amp;client_secret=password&#39;</pre><pre>{&quot;access_token&quot;:&quot;eyJ0eXAiOiJKV1QiLCJ6aXAiOiJOT05FIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiJkZW1vIiwiY3RzIjoiT0FVVEgyX1NUQVRFTEVTU19HUkFOVCIsImF1dGhfbGV2ZWwiOjAsImF1ZGl0VHJhY2tpbmdJZCI6IjY0ZjcxMmFjLWUxZjQtNDJmZi04NTY3LTFlYzg0NGY0YTg5MC0yNDM3NSIsImlzcyI6Imh0dHA6Ly9hdXRodHJlZS5vcGVucm9jay5vcmc6ODA4MC9vcGVuYW0vb2F1dGgyIiwidG9rZW5OYW1lIjoiYWNjZXNzX3Rva2VuIiwidG9rZW5fdHlwZSI6IkJlYXJlciIsImF1dGhHcmFudElkIjoiaktScUd4SkU0ZWFfS21fZkZ0WVREcFhyZDdrIiwiYXVkIjoiZXhhbXBsZSIsIm5iZiI6MTU0NDg5MTU3NywiZ3JhbnRfdHlwZSI6InBhc3N3b3JkIiwic2NvcGUiOlsicmVhZCJdLCJhdXRoX3RpbWUiOjE1NDQ4OTE1NzcsInJlYWxtIjoiLyIsImV4cCI6MTU0NDg5NTE3NywiaWF0IjoxNTQ0ODkxNTc3LCJleHBpcmVzX2luIjozNjAwLCJqdGkiOiI0amxmX25ma01lSFROSFJNUUZuM04yRlY4SEEifQ.8eWcfQ-RGN1X0gNsuMZjf7jkJ7qynbOIrz7QYn34QkY&quot;,&quot;refresh_token&quot;:&quot;...</pre><p>Great, we now have an <strong>Access Token</strong>. However we don’t have any reason to use it yet as our API’s are unprotected. Lets fix that.</p><p><strong><em>Retrieving an Access Token from Forgerock inside Apigee</em></strong></p><p>We’re going to follow the Apigee instructions for this detailed here: <a href="https://docs.apigee.com/api-platform/security/oauth/use-third-party-oauth-system">https://docs.apigee.com/api-platform/security/oauth/use-third-party-oauth-system</a>, specifically the approach detailing <strong>External Validation of Client Credentials</strong>.</p><p>This approach works by having Apigee callout to ForgeRock to issue an OAuth token and later use the token it has stored as part of the verification process.</p><p>As a developer, instead of requesting the access token from ForgeRock directly you instead request it via Apigee which in turn passes the token request on to AM. When AM returns a token, Apigee stores it and presents it back to the calling application.</p><p>In Apigee we need to:</p><ol><li>Make a <strong>Service Callout</strong> to verify client credentials and acquire an access token from AM</li><li><strong>ExtractVariables</strong> to extract the access token.</li><li><strong>Assign Message </strong>to set a well-known-varriable called <strong>oauth_external_authorization_status</strong>.</li><li>Use the <strong>OAuth2 </strong>policy with <strong>GenerateAccessToken</strong> and <strong>ExternalAuthorization</strong> set to <strong>true.</strong></li></ol><p>Firstly lets navigate to our API proxy we created earlier:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*GnZqO9FxHDibKv7aflXxLA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZeKvCzLY7qmS_qYMuMDrbQ.png" /></figure><p>Navigate to the<strong> DEVELOP</strong> tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7XE8tAy8xc-qmxO_SePcBw.png" /></figure><p>Create a new Conditional Flow by hitting <strong>+</strong> on the <strong>default</strong> Proxy Endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*mJKx7Y5K9JmXKiy1W6lmjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*hBQ17BQfzwMfFpiPl3b2Dg.png" /></figure><p>Use the following condition:</p><pre>(proxy.pathsuffix MatchesPath “/access_token**”) and (request.verb = “POST”)</pre><p>Select the new <strong>access_token</strong> flow, it should be empty as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*RZvYrWnOE7Nw7lw8uP3FCw.png" /></figure><p>We will now populate this flow by creating Apigee <strong>Policies. </strong>Press <strong>+</strong> next to <strong>Policies</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*a8iOpnjpapOYpOJWAOIyMg.png" /></figure><p>Add a <strong>Service Callout </strong>policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*YV0zFyb6bY6KvrDO-EngOQ.png" /></figure><p>Then drag and drop the new policy to the <strong>access_token</strong> flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*9ey5OeGvVKe9Dhbc_fPMZQ.png" /></figure><p>Copy and paste the following policy configuration:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;ServiceCallout async=&quot;false&quot; continueOnError=&quot;false&quot; enabled=&quot;true&quot; name=&quot;Get-Access-Token&quot;&gt;<br>    &lt;DisplayName&gt;Get Access Token&lt;/DisplayName&gt;<br>    &lt;Properties/&gt;<br>    &lt;Request clearPayload=&quot;false&quot; variable=&quot;myRequest&quot;&gt;<br>        &lt;Set&gt;<br>            &lt;Verb&gt;POST&lt;/Verb&gt;<br>            &lt;Headers&gt;<br>                &lt;Header name=&quot;Content-Type&quot;&gt;application/x-www-form-urlencoded&lt;/Header&gt;<br>            &lt;/Headers&gt;<br>            &lt;FormParams&gt;<br>                &lt;FormParam name=&quot;grant_type&quot;&gt;password&lt;/FormParam&gt;<br>                &lt;FormParam name=&quot;username&quot;&gt;{request.formparam.username}&lt;/FormParam&gt;<br>                &lt;FormParam name=&quot;password&quot;&gt;{request.formparam.password}&lt;/FormParam&gt;<br>                &lt;FormParam name=&quot;client_id&quot;&gt;{request.formparam.client_id}&lt;/FormParam&gt;<br>                &lt;FormParam name=&quot;client_secret&quot;&gt;{request.formparam.client_secret}&lt;/FormParam&gt;<br>                &lt;FormParam name=&quot;scope&quot;&gt;{request.formparam.scope}&lt;/FormParam&gt;<br>            &lt;/FormParams&gt;<br>        &lt;/Set&gt;<br>        &lt;IgnoreUnresolvedVariables&gt;false&lt;/IgnoreUnresolvedVariables&gt;<br>    &lt;/Request&gt;<br>    &lt;Response&gt;calloutResponse&lt;/Response&gt;<br>    &lt;HTTPTargetConnection&gt;<br>        &lt;Properties/&gt;<br>        &lt;URL&gt;<a href="http://authtree.openrock.org:8080/openam/oauth2/realms/root/access_token">http://authtree.openrock.org:8080/openam/oauth2/realms/root/access_token</a>&lt;/URL&gt;<br>    &lt;/HTTPTargetConnection&gt;<br>&lt;/ServiceCallout&gt;</pre><p><em>This policy basically creates a new HTTP POST payload using the form params sent in the request to the Apigee endpoint and sends that to our </em><strong><em>HTTPTargetConnection</em></strong><em> which in this case is the ForgeRock AM access_token endpoint.</em></p><p>Press <strong>Save</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*bxUA6ndA3vKfrrdn9o6h2w.png" /></figure><p>Create a new <strong>Extract Variables</strong> policy in the same way as before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*EB21c6issJRIxtdCf3yTnQ.png" /></figure><p>Drag it to the <strong>access_token </strong>flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*I8Xp1Xuc2hPWrCgJXh6qFw.png" /></figure><p>Copy and paste the following configuration then <strong>Save.</strong></p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;ExtractVariables async=&quot;false&quot; continueOnError=&quot;false&quot; enabled=&quot;true&quot; name=&quot;Extract-Token&quot;&gt;<br>    &lt;DisplayName&gt;Extract Token&lt;/DisplayName&gt;<br>    &lt;IgnoreUnresolvedVariables&gt;true&lt;/IgnoreUnresolvedVariables&gt;<br>    &lt;JSONPayload&gt;<br>        &lt;Variable name=&quot;forgerock_access_token&quot;&gt;<br>            &lt;JSONPath&gt;$.access_token&lt;/JSONPath&gt;<br>        &lt;/Variable&gt;<br>    &lt;/JSONPayload&gt;<br>    &lt;Source clearPayload=&quot;false&quot;&gt;calloutResponse&lt;/Source&gt;<br>&lt;/ExtractVariables&gt;</pre><p><em>This policy configuration takes the JSON returned from the call to AM access_token endpoint and sets it into a variable called </em><strong><em>forgerock_access_token</em></strong><em>.</em></p><p>Create a new <strong>Assign Message</strong> policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*N_BG42gcCcDiqIMVobAFoA.png" /></figure><p>Drag it to the <strong>access_token </strong>flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*HvL82eUr7bO1o-m-JYlMBA.png" /></figure><p>Copy and paste the following configuration then <strong>Save.</strong></p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;AssignMessage async=&quot;false&quot; continueOnError=&quot;false&quot; enabled=&quot;true&quot; name=&quot;Assign-Message-Set-Variables&quot;&gt;<br>    &lt;DisplayName&gt;Set Ext Authz Status&lt;/DisplayName&gt;<br>    &lt;FaultRules/&gt;<br>    &lt;Properties/&gt;<br>    &lt;AssignVariable&gt;<br>        &lt;Name&gt;oauth_external_authorization_status&lt;/Name&gt;<br>        &lt;Value&gt;true&lt;/Value&gt;<br>    &lt;/AssignVariable&gt;<br>    &lt;IgnoreUnresolvedVariables&gt;true&lt;/IgnoreUnresolvedVariables&gt;<br>    &lt;AssignTo createNew=&quot;false&quot; transport=&quot;http&quot; type=&quot;request&quot;/&gt;<br>&lt;/AssignMessage&gt;</pre><p><em>This policy configuration determines whether Apigee will try to validate the client credentials, in our flow AM has already done this so we can set it to </em><strong><em>true</em></strong><em>.</em></p><p>The final step to allow us to retrieve an access token is to create an <strong>OAuth v2.0</strong> policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*xdfvBj26d09WYrvVBDuzPA.png" /></figure><p>Drag it to the <strong>access_token </strong>flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*GGXoKjDmQQSDTAoCzSQRKQ.png" /></figure><p>Copy and paste the following configuration then <strong>Save.</strong></p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;OAuthV2 name=&quot;OAuth-v20-Store-External-Token&quot;&gt;<br>    &lt;DisplayName&gt;Store Access Token&lt;/DisplayName&gt;<br>    &lt;Attributes/&gt;<br>   &lt;ExternalAccessToken&gt;forgerock_access_token&lt;/ExternalAccessToken&gt;<br>    &lt;ExternalAuthorization&gt;true&lt;/ExternalAuthorization&gt;<br>    &lt;Operation&gt;GenerateAccessToken&lt;/Operation&gt;<br>    &lt;GenerateResponse enabled=&quot;true&quot;&gt;<br>        &lt;Format&gt;FORM_PARAM&lt;/Format&gt;<br>    &lt;/GenerateResponse&gt;<br>    &lt;ReuseRefreshToken&gt;false&lt;/ReuseRefreshToken&gt;<br>    &lt;StoreToken&gt;true&lt;/StoreToken&gt;<br>    &lt;SupportedGrantTypes&gt;<br>        &lt;GrantType&gt;password&lt;/GrantType&gt;<br>    &lt;/SupportedGrantTypes&gt;<br>    &lt;Tokens/&gt;<br>&lt;/OAuthV2&gt;</pre><p><em>This policy configuration tells Apigee the name of the variable holding the access token, in this case</em><strong><em> forgerock_access_token</em></strong><em>. It also sets the supported grant types and importantly tells Apigee to store the access token for later validation.</em></p><p>We’re nearly ready to request an access_token. However before we do so, we <strong>must</strong> create a new <strong>Application</strong> in Apigee and we must make sure there is a matching <strong>Client Application </strong>in<strong> </strong>ForgeRock AM.</p><p>Make sure everything has been saved first. Then go to <strong>Publish.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*Eh9tF9EHQEqYFJ0Nb4QAZQ.png" /></figure><p>Goto<strong> API Products</strong>, <strong>+ API Product</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/137/1*IEANxxo5FmKtZaCJr0WPYw.png" /></figure><p>Give the product a <strong>Name, </strong>and select the <strong>API Proxy </strong>created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y_iOZFSq7B03hmqarPPcvA.png" /></figure><p>Goto<strong> Apps</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/1*VlFbZSfteJrVdjTW3o3BIg.png" /></figure><p>Goto<strong> Apps</strong>, <strong>+App</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/109/1*fdlP9Q8IlMY3DCKtHf39Rw.png" /></figure><p>Enter a <strong>Name</strong>, add a <strong>Developer</strong>, <strong>+</strong> <strong>Product </strong>and add the product created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qRfH5nrIF3UVaKiMOWf2RQ.png" /></figure><p>Now we have an app we need the <strong>Client ID</strong>, in Apigee this the <strong>Consumer Key</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*Lg6FjmeNGSeE-WFUTI_4LA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*gv-3Fq7exdAPIEFbyo-dfQ.png" /></figure><p>The final step is to access AM again as the administrator and create a new OAuth2 Client Application with an ID that matches the <strong>Consumer Key</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKD7XHI1met1i9SBxuhaPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8NTZYotsRqfp0UA67Rf9mg.png" /></figure><p>We should now be able to make a call to our access_token flow in Apigee which will in turn call ForgeRock AM to retrieve a token.</p><pre>curl -X POST \<br>  <a href="http://wayneblacklock-test.apigee.net/forgerock/bank/access_token">http://wayneblacklock-test.apigee.net/forgerock/bank/access_token</a> \<br>  -H &#39;Content-Type: application/x-www-form-urlencoded&#39; \<br>  -d &#39;grant_type=password&amp;username=demo&amp;password=changeit&amp;client_id=qbJdtaJwuUqqPXVnBeKAUlZDi4ToPATG&amp;client_secret=password&amp;scope=read&#39;<br>{<br>  &quot;refresh_token_expires_in&quot; : &quot;0&quot;,<br>  &quot;refresh_token_status&quot; : &quot;approved&quot;,<br>  &quot;api_product_list&quot; : &quot;[ForgeRock]&quot;,<br>  &quot;api_product_list_json&quot; : [ &quot;ForgeRock&quot; ],<br>  &quot;organization_name&quot; : &quot;wayneblacklock&quot;,<br>  &quot;developer.email&quot; : &quot;<a href="/service/mailto:wayne.blacklock@forgerock.com">wayne.blacklock@forgerock.com</a>&quot;,<br>  &quot;token_type&quot; : &quot;BearerToken&quot;,<br>  &quot;issued_at&quot; : &quot;1544966209580&quot;,<br>  &quot;client_id&quot; : &quot;qbJdtaJwuUqqPXVnBeKAUlZDi4ToPATG&quot;,<br>  <strong>&quot;access_token&quot; : &quot;eyJ0eXAiOiJKV1QiLCJ6aXAiOiJOT05FIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiJkZW1vIiwiY3RzIjoiT0FVVEgyX1NUQVRFTEVTU19HUkFOVCIsImF1dGhfbGV2ZWwiOjAsImF1ZGl0VHJhY2tpbmdJZCI6IjY0ZjcxMmFjLWUxZjQtNDJmZi04NTY3LTFlYzg0NGY0YTg5MC00MDA1NjAiLCJpc3MiOiJodHRwOi8vYXV0aHRyZWUub3BlbnJvY2sub3JnOjgwODAvb3BlbmFtL29hdXRoMiIsInRva2VuTmFtZSI6ImFjY2Vzc190b2tlbiIsInRva2VuX3R5cGUiOiJCZWFyZXIiLCJhdXRoR3JhbnRJZCI6IlREZHpfV25zNWpkUkQzckdKZDJUcm9fenBVWSIsImF1ZCI6InFiSmR0YUp3dVVxcVBYVm5CZUtBVWxaRGk0VG9QQVRHIiwibmJmIjoxNTQ0OTY2MjA5LCJncmFudF90eXBlIjoicGFzc3dvcmQiLCJzY29wZSI6WyJyZWFkIl0sImF1dGhfdGltZSI6MTU0NDk2NjIwOSwicmVhbG0iOiIvIiwiZXhwIjoxNTQ0OTY5ODA5LCJpYXQiOjE1NDQ5NjYyMDksImV4cGlyZXNfaW4iOjM2MDAsImp0aSI6Ik5VOC03c1JZZWNRSm5kNVRZTWg0bHo5cHJlZyJ9.EGc3lPowM8lEq9CfedaJRaoh8nb5Oyvkcad8R7hdAGo&quot;,</strong><br>  &quot;refresh_token&quot; : &quot;ReG59I7kfQNp9YOGqGQriL0GmAswKbew&quot;,<br>  &quot;application_name&quot; : &quot;d8e53f28-db9c-47f9-81b4-018e863b4d56&quot;,<br>  &quot;scope&quot; : &quot;&quot;,<br>  &quot;refresh_token_issued_at&quot; : &quot;1544966209580&quot;,<br>  &quot;expires_in&quot; : &quot;1799&quot;,<br>  &quot;refresh_count&quot; : &quot;0&quot;,<br>  &quot;status&quot; : &quot;approved&quot;<br>}“</pre><p>If we decode the access_token we can confirm it was issued by AM:</p><pre>{<br>  &quot;sub&quot;: &quot;demo&quot;,<br>  &quot;cts&quot;: &quot;OAUTH2_STATELESS_GRANT&quot;,<br>  &quot;auth_level&quot;: 0,<br>  &quot;auditTrackingId&quot;: &quot;64f712ac-e1f4-42ff-8567-1ec844f4a890-400560&quot;,<br>  &quot;iss&quot;: &quot;<a href="http://authtree.openrock.org:8080/openam/oauth2">http://authtree.openrock.org:8080/openam/oauth2</a>&quot;,<br>  &quot;tokenName&quot;: &quot;access_token&quot;,<br>  &quot;token_type&quot;: &quot;Bearer&quot;,<br>  &quot;authGrantId&quot;: &quot;TDdz_Wns5jdRD3rGJd2Tro_zpUY&quot;,<br>  &quot;aud&quot;: &quot;qbJdtaJwuUqqPXVnBeKAUlZDi4ToPATG&quot;,<br>  &quot;nbf&quot;: 1544966209,<br>  &quot;grant_type&quot;: &quot;password&quot;,<br>  &quot;scope&quot;: [<br>    &quot;read&quot;<br>  ],<br>  &quot;auth_time&quot;: 1544966209,<br>  &quot;realm&quot;: &quot;/&quot;,<br>  &quot;exp&quot;: 1544969809,<br>  &quot;iat&quot;: 1544966209,<br>  &quot;expires_in&quot;: 3600,<br>  &quot;jti&quot;: &quot;NU8-7sRYecQJnd5TYMh4lz9preg&quot;<br>}</pre><p>We can also use the AM introspect endpoints directly to confirm the validity of the token.</p><pre>curl -X GET \<br>  &#39;<a href="http://authtree.openrock.org:8080/openam/oauth2/realms/root/tokeninfo?access_token=eyJ0eXAiOiJKV1QiLCJ6aXAiOiJOT05FIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiJkZW1vIiwiY3RzIjoiT0FVVEgyX1NUQVRFTEVTU19HUkFOVCIsImF1dGhfbGV2ZWwiOjAsImF1ZGl0VHJhY2tpbmdJZCI6IjY0ZjcxMmFjLWUxZjQtNDJmZi04NTY3LTFlYzg0NGY0YTg5MC00MDA1NjAiLCJpc3MiOiJodHRwOi8vYXV0aHRyZWUub3BlbnJvY2sub3JnOjgwODAvb3BlbmFtL29hdXRoMiIsInRva2VuTmFtZSI6ImFjY2Vzc190b2tlbiIsInRva2VuX3R5cGUiOiJCZWFyZXIiLCJhdXRoR3JhbnRJZCI6IlREZHpfV25zNWpkUkQzckdKZDJUcm9fenBVWSIsImF1ZCI6InFiSmR0YUp3dVVxcVBYVm5CZUtBVWxaRGk0VG9QQVRHIiwibmJmIjoxNTQ0OTY2MjA5LCJncmFudF90eXBlIjoicGFzc3dvcmQiLCJzY29wZSI6WyJyZWFkIl0sImF1dGhfdGltZSI6MTU0NDk2NjIwOSwicmVhbG0iOiIvIiwiZXhwIjoxNTQ0OTY5ODA5LCJpYXQiOjE1NDQ5NjYyMDksImV4cGlyZXNfaW4iOjM2MDAsImp0aSI6Ik5VOC03c1JZZWNRSm5kNVRZTWg0bHo5cHJlZyJ9.EGc3lPowM8lEq9CfedaJRaoh8nb5Oyvkcad8R7hdAGo&#39;">http://authtree.openrock.org:8080/openam/oauth2/realms/root/tokeninfo?access_token=eyJ0eXAiOiJKV1QiLCJ6aXAiOiJOT05FIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiJkZW1vIiwiY3RzIjoiT0FVVEgyX1NUQVRFTEVTU19HUkFOVCIsImF1dGhfbGV2ZWwiOjAsImF1ZGl0VHJhY2tpbmdJZCI6IjY0ZjcxMmFjLWUxZjQtNDJmZi04NTY3LTFlYzg0NGY0YTg5MC00MDA1NjAiLCJpc3MiOiJodHRwOi8vYXV0aHRyZWUub3BlbnJvY2sub3JnOjgwODAvb3BlbmFtL29hdXRoMiIsInRva2VuTmFtZSI6ImFjY2Vzc190b2tlbiIsInRva2VuX3R5cGUiOiJCZWFyZXIiLCJhdXRoR3JhbnRJZCI6IlREZHpfV25zNWpkUkQzckdKZDJUcm9fenBVWSIsImF1ZCI6InFiSmR0YUp3dVVxcVBYVm5CZUtBVWxaRGk0VG9QQVRHIiwibmJmIjoxNTQ0OTY2MjA5LCJncmFudF90eXBlIjoicGFzc3dvcmQiLCJzY29wZSI6WyJyZWFkIl0sImF1dGhfdGltZSI6MTU0NDk2NjIwOSwicmVhbG0iOiIvIiwiZXhwIjoxNTQ0OTY5ODA5LCJpYXQiOjE1NDQ5NjYyMDksImV4cGlyZXNfaW4iOjM2MDAsImp0aSI6Ik5VOC03c1JZZWNRSm5kNVRZTWg0bHo5cHJlZyJ9.EGc3lPowM8lEq9CfedaJRaoh8nb5Oyvkcad8R7hdAGo&#39;</a> \<br>  -H &#39;Content-Type: application/x-www-form-urlencoded&#39; \<br>  -H &#39;cache-control: no-cache&#39;<br>{&quot;sub&quot;:&quot;demo&quot;,&quot;cts&quot;:&quot;OAUTH2_STATELESS_GRANT&quot;,&quot;read&quot;:&quot;&quot;,&quot;auth_level&quot;:0,&quot;auditTrackingId&quot;:&quot;64f712ac-e1f4-42ff-8567-1ec844f4a890-400560&quot;,&quot;iss&quot;:&quot;<a href="http://authtree.openrock.org:8080/openam/oauth2">http://authtree.openrock.org:8080/openam/oauth2</a>&quot;,&quot;tokenName&quot;:&quot;access_token&quot;,&quot;token_type&quot;:&quot;Bearer&quot;,&quot;authGrantId&quot;:&quot;TDdz_Wns5jdRD3rGJd2Tro_zpUY&quot;,&quot;access_token&quot;:&quot;eyJ0eXAiOiJKV1QiLCJ6aXAiOiJOT05FIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiJkZW1vIiwiY3RzIjoiT0FVVEgyX1NUQVRFTEVTU19HUkFOVCIsImF1dGhfbGV2ZWwiOjAsImF1ZGl0VHJhY2tpbmdJZCI6IjY0ZjcxMmFjLWUxZjQtNDJmZi04NTY3LTFlYzg0NGY0YTg5MC00MDA1NjAiLCJpc3MiOiJodHRwOi8vYXV0aHRyZWUub3BlbnJvY2sub3JnOjgwODAvb3BlbmFtL29hdXRoMiIsInRva2VuTmFtZSI6ImFjY2Vzc190b2tlbiIsInRva2VuX3R5cGUiOiJCZWFyZXIiLCJhdXRoR3JhbnRJZCI6IlREZHpfV25zNWpkUkQzckdKZDJUcm9fenBVWSIsImF1ZCI6InFiSmR0YUp3dVVxcVBYVm5CZUtBVWxaRGk0VG9QQVRHIiwibmJmIjoxNTQ0OTY2MjA5LCJncmFudF90eXBlIjoicGFzc3dvcmQiLCJzY29wZSI6WyJyZWFkIl0sImF1dGhfdGltZSI6MTU0NDk2NjIwOSwicmVhbG0iOiIvIiwiZXhwIjoxNTQ0OTY5ODA5LCJpYXQiOjE1NDQ5NjYyMDksImV4cGlyZXNfaW4iOjM2MDAsImp0aSI6Ik5VOC03c1JZZWNRSm5kNVRZTWg0bHo5cHJlZyJ9.EGc3lPowM8lEq9CfedaJRaoh8nb5Oyvkcad8R7hdAGo&quot;,&quot;aud&quot;:&quot;qbJdtaJwuUqqPXVnBeKAUlZDi4ToPATG&quot;,&quot;nbf&quot;:1544966209,&quot;grant_type&quot;:&quot;password&quot;,&quot;scope&quot;:[&quot;read&quot;],&quot;auth_time&quot;:1544966209,&quot;realm&quot;:&quot;/&quot;,&quot;exp&quot;:1544969809,&quot;iat&quot;:1544966209,&quot;expires_in&quot;:3600,&quot;jti&quot;:&quot;NU8-7sRYecQJnd5TYMh4lz9preg&quot;}“</pre><h3>Protecting the API with OAuth 2.0</h3><p>We can now retrieve an access token, we just need a protected API to access it with, lets OAuth enable our API from earlier.</p><p>Create a new conditional flow on the <strong>default</strong> Target Endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*6eJvAJv8qhiF8Cpr8WBP8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*I5QAueokP13bSaBnV7IKnw.png" /></figure><p>Create a new <strong>OAuth v2.0</strong> policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*qOBSPX1WCexmXIicVTvpOQ.png" /></figure><p>Configure the policy as follows.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;OAuthV2 async=&quot;false&quot; continueOnError=&quot;false&quot; enabled=&quot;true&quot; name=&quot;Verify-Access-Token&quot;&gt;<br>    &lt;DisplayName&gt;Verify Access Token&lt;/DisplayName&gt;<br>    &lt;Properties/&gt;<br>    &lt;Attributes/&gt;<br>    &lt;ExternalAuthorization&gt;true&lt;/ExternalAuthorization&gt;<br>    &lt;Operation&gt;VerifyAccessToken&lt;/Operation&gt;<br>    &lt;SupportedGrantTypes/&gt;<br>    &lt;GenerateResponse enabled=&quot;false&quot;/&gt;<br>    &lt;Tokens/&gt;<br>&lt;/OAuthV2&gt;</pre><p>And drag it over to the flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*ZGmNhgfn7Jt6llkbduNRVw.png" /></figure><p>Now try accessing the API from earlier, we should see an error from Apigee stating our access token is invalid.</p><pre>curl -X GET \<br>  <a href="http://wayneblacklock-test.apigee.net/forgerock/bank/api/wblacklock">http://wayneblacklock-test.apigee.net/forgerock/bank/api/wblacklock</a><br>{&quot;fault&quot;:{&quot;faultstring&quot;:&quot;Invalid access token&quot;,&quot;detail&quot;:{&quot;errorcode&quot;:&quot;oauth.v2.InvalidAccessToken&quot;}}}“</pre><p>The token from earlier has probably expired by now, so repeat the call to the <strong>access_token</strong> flow to generate a new access token and when you have it try calling the API using it for <strong>Authorization</strong>.</p><pre>curl -X GET \<br>  <a href="http://wayneblacklock-test.apigee.net/forgerock/bank/api/wblacklock">http://wayneblacklock-test.apigee.net/forgerock/bank/api/wblacklock</a> \<br>  -H &#39;<strong>Authorization: Bearer eyJ0eXAiOiJKV1QiLCJ6aXAiOiJOT05FIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiJkZW1vIiwiY3RzIjoiT0FVVEgyX1NUQVRFTEVTU19HUkFOVCIsImF1dGhfbGV2ZWwiOjAsImF1ZGl0VHJhY2tpbmdJZCI6IjY0ZjcxMmFjLWUxZjQtNDJmZi04NTY3LTFlYzg0NGY0YTg5MC00MTQ4NDEiLCJpc3MiOiJodHRwOi8vYXV0aHRyZWUub3BlbnJvY2sub3JnOjgwODAvb3BlbmFtL29hdXRoMiIsInRva2VuTmFtZSI6ImFjY2Vzc190b2tlbiIsInRva2VuX3R5cGUiOiJCZWFyZXIiLCJhdXRoR3JhbnRJZCI6IkJMMjFkNXlPU0pfeldkYkRmSjIxX05aVWhHMCIsImF1ZCI6InFiSmR0YUp3dVVxcVBYVm5CZUtBVWxaRGk0VG9QQVRHIiwibmJmIjoxNTQ0OTY5MDQ4LCJncmFudF90eXBlIjoicGFzc3dvcmQiLCJzY29wZSI6WyJyZWFkIl0sImF1dGhfdGltZSI6MTU0NDk2OTA0OCwicmVhbG0iOiIvIiwiZXhwIjoxNTQ0OTcyNjQ4LCJpYXQiOjE1NDQ5NjkwNDgsImV4cGlyZXNfaW4iOjM2MDAsImp0aSI6ImRMSXBVcXVNTEprUURHckwzMEphVVc4NEc0MCJ9.qcO5cbguA-Y2A4ogHpX8eAiZqxxc1twSya-b7JxyiYQ</strong>&#39;<br>{&quot;_id&quot;:&quot;wblacklock&quot;,&quot;_rev&quot;:&quot;5&quot;,&quot;frdpmfapref&quot;:&quot;push&quot;,&quot;resourceSet...}</pre><p>Thats it. We are accessing the same API as we were at the very start but this time we need an <strong>access token </strong>to do so, and in this case the access token is being generated by ForgeRock AM.</p><p>There is <em>much more</em> that can be done here and this is intended to be a very simple exercise to prove that integration is possible and get you up and running quickly.</p><p>Feedback is very welcome! Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=322e315c89e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>