Skip to content

Commit dc32ac7

Browse files
committed
fix revoke code to make more sense
1 parent 8d844ba commit dc32ac7

4 files changed

Lines changed: 28 additions & 34 deletions

File tree

‎Article.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@ This revocation mechanism allows an application to invalidate its tokens if the
720720

721721
The API requires the following HTTP Header and Credential parameter information:
722722
- Header:
723-
* Authorization = ```Authorization: Basic <App Key+":" in Base64>```
723+
* Authorization = ```Basic <App Key+":" in Base64 format>```
724+
724725
- Body parameter
725726
* token: The current ```Access Token``` value from the previous RDP Authentication call
726727

@@ -745,15 +746,14 @@ token={current_Access_token}
745746
- Please be noticed **":"** string after the **App Key**.
746747
- The ```/revoke``` endpoint does not use the ```password``` in a Basic Authorization, so we need to send empty password in ```AppKey:``` format.
747748

749+
I am demonstrating with the Python [requests](https://requests.readthedocs.io/) library. We can use the ```auth(clientid,'')``` to the ```requests.post``` function, and the library handles the base64 conversion for us.
750+
751+
If you are using other languages or libraries (like C#), you may need to convert the ```App-Key:``` to based64 ascii string by your self.
752+
748753
Python code:
749754

750755
```Python
751756
#step 7 - Revoking Token
752-
import base64
753-
754-
clientId_bytes = f'{clientId}:'.encode('ascii') #Please be noticed ":" string after the app-key
755-
base64_bytes = base64.b64encode(clientId_bytes)
756-
clientId_base64 = base64_bytes.decode('ascii')
757757

758758
# Send HTTP Request
759759
auth_url = f'{RDP_HOST}/auth/oauth2/v1/revoke'
@@ -763,10 +763,10 @@ auth_response = None
763763
try:
764764
auth_response = requests.post(auth_url,
765765
headers = {
766-
'Content-Type':'application/x-www-form-urlencoded',
767-
'Authorization': f'Basic {clientId_base64}'
766+
'Content-Type':'application/x-www-form-urlencoded'
768767
},
769-
data = payload
768+
data = payload,
769+
auth = (clientId, '')
770770
)
771771
except requests.exceptions.RequestException as exp:
772772
print(f'Caught exception: {exp}')

‎RDP-Generic-CFS.html‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8772,7 +8772,7 @@ <h3 id="Step-7:-Revoke-Token-to-ending-the-session.">Step 7: Revoke Token to end
87728772
<ul>
87738773
<li><p>Header:</p>
87748774
<ul>
8775-
<li>Authorization = <code>Basic &lt;App Key+":" in Base64&gt;</code></li>
8775+
<li>Authorization = <code>Basic &lt;App Key+":" in Base64 format&gt;</code></li>
87768776
</ul>
87778777
</li>
87788778
<li><p>Body parameter</p>
@@ -8801,6 +8801,8 @@ <h3 id="Step-7:-Revoke-Token-to-ending-the-session.">Step 7: Revoke Token to end
88018801
<li>Please be noticed <strong>":"</strong> string after the <strong>App Key</strong>.</li>
88028802
<li>The <code>/revoke</code> endpoint does not use the <code>password</code> in a Basic Authorization, so we need to send empty password in <code>AppKey:</code> format.</li>
88038803
</ul>
8804+
<p>I am demonstrating with the Python <a href="https://requests.readthedocs.io/">requests</a> library. We can use the <code>auth(clientid,'')</code> to the <code>requests.post</code> function, and the library handles the base64 conversion for us.</p>
8805+
<p>If you are using other languages or libraries (like C#), you may need to convert the <code>App-Key:</code> to based64 ascii string by your self.</p>
88048806
</div>
88058807
</div>
88068808
</div>
@@ -8814,24 +8816,18 @@ <h3 id="Step-7:-Revoke-Token-to-ending-the-session.">Step 7: Revoke Token to end
88148816
<div class="cm-editor cm-s-jupyter">
88158817
<div class="highlight hl-ipython3"><pre><span></span><span class="c1">#step 7 - Revoking Token</span>
88168818

8817-
<span class="kn">import</span><span class="w"> </span><span class="nn">base64</span>
8818-
8819-
<span class="n">clientId_bytes</span> <span class="o">=</span> <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">clientId</span><span class="si">}</span><span class="s1">:'</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'ascii'</span><span class="p">)</span> <span class="c1">#Please be noticed ":" string after the app-key</span>
8820-
<span class="n">base64_bytes</span> <span class="o">=</span> <span class="n">base64</span><span class="o">.</span><span class="n">b64encode</span><span class="p">(</span><span class="n">clientId_bytes</span><span class="p">)</span>
8821-
<span class="n">clientId_base64</span> <span class="o">=</span> <span class="n">base64_bytes</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'ascii'</span><span class="p">)</span>
8822-
88238819
<span class="c1"># Send HTTP Request</span>
88248820
<span class="n">auth_url</span> <span class="o">=</span> <span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">RDP_HOST</span><span class="si">}</span><span class="s1">/auth/oauth2/v1/revoke'</span>
88258821
<span class="n">payload</span> <span class="o">=</span> <span class="sa">f</span><span class="s1">'token=</span><span class="si">{</span><span class="n">access_token</span><span class="si">}</span><span class="s1">'</span>
88268822
<span class="n">auth_response</span> <span class="o">=</span> <span class="kc">None</span>
88278823

88288824
<span class="k">try</span><span class="p">:</span>
88298825
<span class="n">auth_response</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">auth_url</span><span class="p">,</span>
8830-
<span class="n">headers</span> <span class="o">=</span> <span class="p">{</span>
8831-
<span class="s1">'Content-Type'</span><span class="p">:</span><span class="s1">'application/x-www-form-urlencoded'</span><span class="p">,</span>
8832-
<span class="s1">'Authorization'</span><span class="p">:</span> <span class="sa">f</span><span class="s1">'Basic </span><span class="si">{</span><span class="n">clientId_base64</span><span class="si">}</span><span class="s1">'</span>
8833-
<span class="p">},</span>
8834-
<span class="n">data</span> <span class="o">=</span> <span class="n">payload</span>
8826+
<span class="n">headers</span> <span class="o">=</span> <span class="p">{</span>
8827+
<span class="s1">'Content-Type'</span><span class="p">:</span><span class="s1">'application/x-www-form-urlencoded'</span>
8828+
<span class="p">},</span>
8829+
<span class="n">data</span> <span class="o">=</span> <span class="n">payload</span><span class="p">,</span>
8830+
<span class="n">auth</span> <span class="o">=</span> <span class="p">(</span><span class="n">clientId</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span>
88358831
<span class="p">)</span>
88368832
<span class="k">except</span> <span class="n">requests</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">RequestException</span> <span class="k">as</span> <span class="n">exp</span><span class="p">:</span>
88378833
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">'Caught exception: </span><span class="si">{</span><span class="n">exp</span><span class="si">}</span><span class="s1">'</span><span class="p">)</span>

‎RDP-Generic-CFS.ipynb‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@
10771077
"\n",
10781078
"The API requires the following HTTP Header and Credential parameter information:\n",
10791079
"- Header: \n",
1080-
" * Authorization = ```Basic <App Key+\":\" in Base64>```\n",
1080+
" * Authorization = ```Basic <App Key+\":\" in Base64 format>```\n",
10811081
"\n",
10821082
"- Body parameter\n",
10831083
" * token: The current ```Access Token``` value from the previous RDP Authentication call\n",
@@ -1101,7 +1101,11 @@
11011101
"\n",
11021102
"**Note**: \n",
11031103
"- Please be noticed **\":\"** string after the **App Key**. \n",
1104-
"- The ```/revoke``` endpoint does not use the ```password``` in a Basic Authorization, so we need to send empty password in ```AppKey:``` format."
1104+
"- The ```/revoke``` endpoint does not use the ```password``` in a Basic Authorization, so we need to send empty password in ```AppKey:``` format.\n",
1105+
"\n",
1106+
"I am demonstrating with the Python [requests](https://requests.readthedocs.io/) library. We can use the ```auth(clientid,'')``` to the ```requests.post``` function, and the library handles the base64 conversion for us.\n",
1107+
"\n",
1108+
"If you are using other languages or libraries (like C#), you may need to convert the ```App-Key:``` to based64 ascii string by your self.\n"
11051109
]
11061110
},
11071111
{
@@ -1121,24 +1125,18 @@
11211125
"source": [
11221126
"#step 7 - Revoking Token\n",
11231127
"\n",
1124-
"import base64\n",
1125-
"\n",
1126-
"clientId_bytes = f'{clientId}:'.encode('ascii') #Please be noticed \":\" string after the app-key\n",
1127-
"base64_bytes = base64.b64encode(clientId_bytes)\n",
1128-
"clientId_base64 = base64_bytes.decode('ascii')\n",
1129-
"\n",
11301128
"# Send HTTP Request\n",
11311129
"auth_url = f'{RDP_HOST}/auth/oauth2/v1/revoke'\n",
11321130
"payload = f'token={access_token}'\n",
11331131
"auth_response = None\n",
11341132
"\n",
11351133
"try:\n",
11361134
" auth_response = requests.post(auth_url, \n",
1137-
" headers = {\n",
1138-
" 'Content-Type':'application/x-www-form-urlencoded',\n",
1139-
" 'Authorization': f'Basic {clientId_base64}'\n",
1140-
" }, \n",
1141-
" data = payload\n",
1135+
" headers = {\n",
1136+
" 'Content-Type':'application/x-www-form-urlencoded'\n",
1137+
" }, \n",
1138+
" data = payload,\n",
1139+
" auth = (clientId, '')\n",
11421140
" )\n",
11431141
"except requests.exceptions.RequestException as exp:\n",
11441142
" print(f'Caught exception: {exp}')\n",

‎RDP-Generic-CFS.pdf‎

-2.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)