helpcenter/helpcenter.r7-office.ru/Web/Controls/Help/Portals/Auth.ascx

94 lines
3.5 KiB
Plaintext
Raw Normal View History

2019-02-13 12:53:47 +00:00
<%@ Control Language="C#" Inherits="BaseContentUserControls" %>
<script runat="server">
protected override void Init()
{
PageTitle = PageCaption = "Authentication";
MetaKeyWords = "";
MetaDescription = "";
}
</script>
<div class="MainHelpCenter PageGuides">
<h1>
<span class="hdr">How to pass authentication?</span>
</h1>
<p>One needs to perform several easy steps to pass authentication:</p>
<ol>
<li>Send POST request, containing two parameters: <b>userName</b> and <b>password</b>, to the <a href="<%=VirtualPathUtility.ToAbsolute("~/api/portals/section.aspx?section=authentication")%>">api/2.0/authentication</a> address
2019-02-13 12:53:47 +00:00
<div class="header-gray">Authentication Request</div>
<pre>
POST /api/2.0/authentication.json HTTP/1.1
Host: yourportal.onlyoffice.com
Content-Type: application/json
Accept: application/json
{
"userName": "yourusername",
"password": "yourpassword"
}
</pre>
<div class="note">Please note, that you have to enter your own portal address to the <em>Host: yourportal.onlyoffice.com</em> line instead of yourportal.onlyoffice.com address.</div>
<div class="header-gray">Response</div>
<pre>
HTTP/1.1 201 Created
Cache-Control: private
Content-Type: application/json; charset=utf-8
{
"count": 1,
"response": {
"expires": "2010-07-07T17:06:03.5845502+03:00",
"token": "sdjhfskjdhkqy739459234"
},
"status": 0,
"statusCode": 201
}
</pre>
</li>
<li>In case authentication is successful, a token which will look like <b>sdjhfskjdhkqy739459234</b> will be received</li>
<li>Use this token every time you call API methods inserting it to the HTTP Header: Authorization
<div class="header-gray">Sample API Request</div>
<pre>
GET api/2.0/people/@self.json HTTP/1.1
Host: yourportal.onlyoffice.com
Accept: application/json
Authorization:sdjhfskjdhkqy739459234
</pre>
<div class="note">Please note, that you have to enter your own portal address to the <em>Host: yourportal.onlyoffice.com</em> line instead of yourportal.onlyoffice.com address.</div>
</li>
</ol>
<div id="csharp" class="header-gray">C# authentication request example</div>
<pre>
var request = System.Net.WebRequest.Create("https://yourportal.onlyoffice.com/api/2.0/authentication.json");
request.Method = "POST";
request.ContentType = "application/json";
var body = "{\"userName\":\"yourusername\",\"password\":\"yourpassword\"}";
var data = System.Text.Encoding.UTF8.GetBytes(body);
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (System.Net.HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
</pre>
<div class="note">Please note, that you have to enter your own portal address to the <em>yourportal.onlyoffice.com</em> line instead of yourportal.onlyoffice.com address.</div>
<div id="curl" class="header-gray">cURL authentication request example</div>
<pre>
curl --request POST --header "Content-Type: application/json" --data "{\"username\":\"yourusername\",\"password\":\"yourpassword\"}" "https://yourportal.onlyoffice.com/api/2.0/authentication.json"
</pre>
<div class="note">Please note, that you have to enter your own portal address to the <em>yourportal.onlyoffice.com</em> line instead of yourportal.onlyoffice.com address.</div>
</div>