forked from laiweijian4/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Wang , Deng Ke <wangdengke2@huawei.com> Co-committed-by: Wang , Deng Ke <wangdengke2@huawei.com>
71 lines
7.9 KiB
HTML
71 lines
7.9 KiB
HTML
<a name="dds_api_0010"></a><a name="dds_api_0010"></a>
|
|
|
|
<h1 class="topictitle1">Token Authentication</h1>
|
|
<div id="body1562038443100"><div class="section" id="dds_api_0010__en-us_topic_0110967262_section50237402"><h4 class="sectiontitle">Application Scenarios</h4><p class="MsoNormal" id="dds_api_0010__en-us_topic_0110967262_p27738717">If you use a token for authentication, you must obtain the user's token and add <strong id="dds_api_0010__b842352706134841">X-Auth-Token</strong> to the request message header of the service API when making an API call.</p>
|
|
<p class="MsoNormal" id="dds_api_0010__en-us_topic_0110967262_p48321862">This section describes how to make an API call for token authentication.</p>
|
|
</div>
|
|
<div class="section" id="dds_api_0010__en-us_topic_0110967262_section49483440"><h4 class="sectiontitle">Invoking an API</h4><ol id="dds_api_0010__en-us_topic_0110967262_ol02801474297"><li id="dds_api_0010__en-us_topic_0110967262_li14280177102918"><a name="dds_api_0010__en-us_topic_0110967262_li14280177102918"></a><a name="en-us_topic_0110967262_li14280177102918"></a><span>Obtain the following information:</span><p><ol type="a" id="dds_api_0010__en-us_topic_0110967262_ol5389726173113"><li id="dds_api_0010__en-us_topic_0110967262_li93891526133111">To obtain the IAM endpoint and region name in the message body, see <a href="https://docs.otc.t-systems.com/en-us/endpoint/index.html" target="_blank" rel="noopener noreferrer">Regions and Endpoints</a>.</li><li id="dds_api_0010__en-us_topic_0110967262_li16899152173219">To obtain the project ID, see <a href="dds_projectid.html">Obtaining a Project ID</a>.</li></ol>
|
|
</p></li><li id="dds_api_0010__en-us_topic_0110967262_li109381224173013"><a name="dds_api_0010__en-us_topic_0110967262_li109381224173013"></a><a name="en-us_topic_0110967262_li109381224173013"></a><span>Send a POST https://<em id="dds_api_0010__i79544341571">IAM</em><em id="dds_api_0010__i129551348570">_Endpoint</em>/v3/auth/tokens request to obtain the user token.</span><p>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dds_api_0010__en-us_topic_0110967262_table18389930" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Header description</caption><thead align="left"><tr id="dds_api_0010__en-us_topic_0110967262_row24749807"><th align="left" class="cellrowborder" valign="top" width="25%" id="mcps1.3.2.2.2.2.1.2.5.1.1"><p id="dds_api_0010__en-us_topic_0110967262_p58577354"><strong id="dds_api_0010__b842352706102328">Name</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="28.98%" id="mcps1.3.2.2.2.2.1.2.5.1.2"><p id="dds_api_0010__en-us_topic_0110967262_p47145209"><strong id="dds_api_0010__b84235270611143">Description</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="21.02%" id="mcps1.3.2.2.2.2.1.2.5.1.3"><p id="dds_api_0010__en-us_topic_0110967262_p60665573"><strong id="dds_api_0010__b842352706102346">Mandatory</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="25%" id="mcps1.3.2.2.2.2.1.2.5.1.4"><p id="dds_api_0010__en-us_topic_0110967262_p14964341"><strong id="dds_api_0010__b842352706103845">Example</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dds_api_0010__en-us_topic_0110967262_row4152081"><td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.2.2.2.2.1.2.5.1.1 "><p id="dds_api_0010__en-us_topic_0110967262_p774306">Content-Type</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="28.98%" headers="mcps1.3.2.2.2.2.1.2.5.1.2 "><p id="dds_api_0010__en-us_topic_0110967262_p62718864">Specifies the MIME type of the request body.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="21.02%" headers="mcps1.3.2.2.2.2.1.2.5.1.3 "><p id="dds_api_0010__en-us_topic_0110967262_p47063234">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="25%" headers="mcps1.3.2.2.2.2.1.2.5.1.4 "><p id="dds_api_0010__en-us_topic_0110967262_p54025633">application/json</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="p" id="dds_api_0010__en-us_topic_0110967262_p5008546913818">An example request message is as follows:<pre class="codeblock" id="dds_api_0010__en-us_topic_0110967262_codeblock38470664113529">{
|
|
"auth": {
|
|
"identity": {
|
|
"methods": [
|
|
"password"
|
|
],
|
|
"password": {
|
|
"user": {
|
|
"name": "<em id="dds_api_0010__en-us_topic_0110967262_i1322869015296">username</em>",
|
|
"password": "<em id="dds_api_0010__en-us_topic_0110967262_i15294466152910">password</em>",
|
|
"domain": {
|
|
"name": "<em id="dds_api_0010__en-us_topic_0110967262_i65968558152916">domainname</em>"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"scope": {
|
|
"project": {
|
|
"id": "<em id="dds_api_0010__en-us_topic_0110967262_i1597017249262">project_id</em>"
|
|
}
|
|
}
|
|
}
|
|
}</pre>
|
|
</div>
|
|
<p id="dds_api_0010__en-us_topic_0110967262_p66017215522">In the preceding command, replace parameter in italic with the actual values. For details, see the "Obtaining a User Token" section in the <em id="dds_api_0010__i946718476572">Identity and Access Management API Reference</em>.</p>
|
|
<ol type="a" id="dds_api_0010__en-us_topic_0110967262_ol175844414443"><li id="dds_api_0010__en-us_topic_0110967262_li67598449449"><strong id="dds_api_0010__b1786123819588"><em id="dds_api_0010__i178573811588">IAM</em><em id="dds_api_0010__i185838205815">_Endpoint</em></strong>: Replace it with the IAM endpoint obtained in <a href="#dds_api_0010__en-us_topic_0110967262_li14280177102918">1</a>.</li><li id="dds_api_0010__en-us_topic_0110967262_li475915446448"><strong id="dds_api_0010__b135069585586"><em id="dds_api_0010__i8505758185811">username</em></strong> and <strong id="dds_api_0010__b135077584589"><em id="dds_api_0010__i15071586583">password</em></strong>: Replace them respectively with the username and password of the IAM server.</li><li id="dds_api_0010__en-us_topic_0110967262_li1975924414448"><strong id="dds_api_0010__b05190415590"><em id="dds_api_0010__i10517134175910">project_id</em></strong>: Replace it with the project ID obtained in <a href="#dds_api_0010__en-us_topic_0110967262_li14280177102918">1</a>.</li></ol>
|
|
<p id="dds_api_0010__en-us_topic_0110967262_p1495941365018">After the request is processed, the value of <strong id="dds_api_0010__b349720294597">X-Subject-Token</strong> in the header is the token value.</p>
|
|
<pre class="screen" id="dds_api_0010__en-us_topic_0110967262_screen1094517139545"><strong id="dds_api_0010__en-us_topic_0110967262_b694961335414">X-Subject-Token</strong>:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...</pre>
|
|
</p></li><li id="dds_api_0010__en-us_topic_0110967262_li72803712916"><span>Run the following command to set the token as an environment variable for subsequent operations:</span><p><p id="dds_api_0010__en-us_topic_0110967262_p156940011577"><strong id="dds_api_0010__en-us_topic_0110967262_b138391246125815">export Token=<em id="dds_api_0010__en-us_topic_0110967262_i483954615817">{</em></strong><em id="dds_api_0010__en-us_topic_0110967262_i68411461584">X-Subject-Token</em><strong id="dds_api_0010__en-us_topic_0110967262_b583916465588"><em id="dds_api_0010__en-us_topic_0110967262_i38391446195813">}</em></strong></p>
|
|
<p id="dds_api_0010__en-us_topic_0110967262_p146941401579"><strong id="dds_api_0010__b12263124204"><em id="dds_api_0010__i126320241205">X-Subject-Token</em></strong>: Replace it with the token obtained in <a href="#dds_api_0010__en-us_topic_0110967262_li109381224173013">2</a>. An example command is as follows:</p>
|
|
<p id="dds_api_0010__en-us_topic_0110967262_p1269418014572"><strong id="dds_api_0010__en-us_topic_0110967262_b748349195912">export Token=MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...</strong></p>
|
|
</p></li></ol>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dds_api_0007.html">Environment Preparations</a></div>
|
|
</div>
|
|
</div>
|
|
|