-
Notifications
You must be signed in to change notification settings - Fork 113
feat: Добавление ТокенДоступа (AccessToken) #1571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Stivo182
wants to merge
8
commits into
EvilBeaver:develop
Choose a base branch
from
Stivo182:feat/jwt
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+878
−23
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0ea8852
feat: Добавление ТокенДоступа (AccessToken)
Stivo182 06dfd39
Обязательный process
Stivo182 165b2ea
Использование Jwt классов. Поддержка произвольных значений payload
Stivo182 b620f46
Проверка типа у ключей заголовков, полезной нагрузки и типа значений …
Stivo182 0f2efbd
Добавлены тесты
Stivo182 29f9a34
Доработан тест
Stivo182 a4053d1
Merge branch 'develop' into feat/jwt
Stivo182 ea2fd0e
Приватные тестовые ключи вынесены отдельными файлами
Stivo182 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ This Source Code Form is subject to the terms of the | |
| using System.Text; | ||
| using OneScript.Contexts; | ||
| using OneScript.Exceptions; | ||
| using OneScript.Execution; | ||
| using OneScript.StandardLibrary.Collections; | ||
| using OneScript.Types; | ||
| using RegExp = System.Text.RegularExpressions; | ||
|
|
@@ -130,9 +131,9 @@ public int Timeout | |
| /// <param name="output">Строка. Имя файла, в который нужно записать ответ. Необязательный параметр.</param> | ||
| /// <returns>HTTPОтвет. Ответ сервера.</returns> | ||
| [ContextMethod("Получить", "Get")] | ||
| public HttpResponseContext Get(HttpRequestContext request, string output = null) | ||
| public HttpResponseContext Get(IBslProcess process, HttpRequestContext request, string output = null) | ||
| { | ||
| return GetResponse(request, "GET", output); | ||
| return GetResponse(process, request, "GET", output); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -141,9 +142,9 @@ public HttpResponseContext Get(HttpRequestContext request, string output = null) | |
| /// <param name="request">HTTPЗапрос. Данные и заголовки запроса http</param> | ||
| /// <returns>HTTPОтвет. Ответ сервера.</returns> | ||
| [ContextMethod("Записать", "Put")] | ||
| public HttpResponseContext Put(HttpRequestContext request) | ||
| public HttpResponseContext Put(IBslProcess process, HttpRequestContext request) | ||
| { | ||
| return GetResponse(request, "PUT"); | ||
| return GetResponse(process, request, "PUT", null); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -153,9 +154,9 @@ public HttpResponseContext Put(HttpRequestContext request) | |
| /// <param name="output">Строка. Имя файла, в который нужно записать ответ. Необязательный параметр.</param> | ||
| /// <returns>HTTPОтвет. Ответ сервера.</returns> | ||
| [ContextMethod("ОтправитьДляОбработки", "Post")] | ||
| public HttpResponseContext Post(HttpRequestContext request, string output = null) | ||
| public HttpResponseContext Post(IBslProcess process, HttpRequestContext request, string output = null) | ||
| { | ||
| return GetResponse(request, "POST", output); | ||
| return GetResponse(process, request, "POST", output); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -164,9 +165,9 @@ public HttpResponseContext Post(HttpRequestContext request, string output = null | |
| /// <param name="request">HTTPЗапрос. Данные и заголовки запроса http</param> | ||
| /// <returns>HTTPОтвет. Ответ сервера.</returns> | ||
| [ContextMethod("Удалить", "Delete")] | ||
| public HttpResponseContext Delete(HttpRequestContext request) | ||
| public HttpResponseContext Delete(IBslProcess process, HttpRequestContext request) | ||
| { | ||
| return GetResponse(request, "DELETE"); | ||
| return GetResponse(process, request, "DELETE"); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -175,9 +176,9 @@ public HttpResponseContext Delete(HttpRequestContext request) | |
| /// <param name="request">HTTPЗапрос. Данные и заголовки запроса http</param> | ||
| /// <returns>HTTPОтвет. Ответ сервера.</returns> | ||
| [ContextMethod("Изменить", "Patch")] | ||
| public HttpResponseContext Patch(HttpRequestContext request) | ||
| public HttpResponseContext Patch(IBslProcess process, HttpRequestContext request) | ||
| { | ||
| return GetResponse(request, "PATCH"); | ||
| return GetResponse(process, request, "PATCH"); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -186,9 +187,9 @@ public HttpResponseContext Patch(HttpRequestContext request) | |
| /// <param name="request">HTTPЗапрос. Данные и заголовки запроса http</param> | ||
| /// <returns>HTTPОтвет. Ответ сервера.</returns> | ||
| [ContextMethod("ПолучитьЗаголовки", "Head")] | ||
| public HttpResponseContext Head(HttpRequestContext request) | ||
| public HttpResponseContext Head(IBslProcess process, HttpRequestContext request) | ||
| { | ||
| return GetResponse(request, "HEAD"); | ||
| return GetResponse(process, request, "HEAD"); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -199,9 +200,9 @@ public HttpResponseContext Head(HttpRequestContext request) | |
| /// <param name="output">Строка. Имя выходного файла</param> | ||
| /// <returns>HTTPОтвет. Ответ сервера.</returns> | ||
| [ContextMethod("ВызватьHTTPМетод", "CallHTTPMethod")] | ||
| public HttpResponseContext Patch(string method, HttpRequestContext request, string output = null) | ||
| public HttpResponseContext CallHTTPMethod(IBslProcess process, string method, HttpRequestContext request, string output = null) | ||
| { | ||
| return GetResponse(request, method, output); | ||
| return GetResponse(process, request, method, output); | ||
| } | ||
|
|
||
| private HttpWebRequest CreateRequest(string resource) | ||
|
|
@@ -335,12 +336,12 @@ private static List<Range> ParseRange(string rangeHeader) | |
| return range; | ||
| } | ||
|
|
||
| private HttpResponseContext GetResponse(HttpRequestContext request, string method, string output = null) | ||
| private HttpResponseContext GetResponse(IBslProcess process, HttpRequestContext request, string method, string output = null) | ||
| { | ||
| var webRequest = CreateRequest(request.ResourceAddress); | ||
| webRequest.AllowAutoRedirect = AllowAutoRedirect; | ||
| webRequest.Method = method; | ||
| SetRequestHeaders(request, webRequest); | ||
| SetRequestHeaders(request, webRequest, process); | ||
|
|
||
| if (ContentBodyAllowed(method)) | ||
| SetRequestBody(request, webRequest); | ||
|
|
@@ -385,7 +386,7 @@ private static void SetRequestBody(HttpRequestContext request, HttpWebRequest we | |
| } | ||
| } | ||
|
|
||
| private static void SetRequestHeaders(HttpRequestContext request, HttpWebRequest webRequest) | ||
| private static void SetRequestHeaders(HttpRequestContext request, HttpWebRequest webRequest, IBslProcess process) | ||
| { | ||
| foreach (var item in request.Headers.Select(x => x.GetRawValue() as KeyAndValueImpl)) | ||
| { | ||
|
|
@@ -483,15 +484,19 @@ private static void SetRequestHeaders(HttpRequestContext request, HttpWebRequest | |
| default: | ||
| webRequest.Headers.Set(key, value); | ||
| break; | ||
|
|
||
| } | ||
| } | ||
|
|
||
| // fix #1151 | ||
| if (webRequest.UserAgent == default) | ||
| { | ||
| webRequest.UserAgent = $"1Script v${Assembly.GetExecutingAssembly().GetName().Version}"; | ||
| } | ||
| // fix #1151 | ||
| if (webRequest.UserAgent == default) | ||
| { | ||
| webRequest.UserAgent = $"1Script v${Assembly.GetExecutingAssembly().GetName().Version}"; | ||
| } | ||
|
|
||
| if (request.AccessToken != null) | ||
| { | ||
| string token = request.AccessToken.ToString(process); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Упадет, если null. (везде в методах он необязательный со значением null по умолчанию)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Сделал обязательным process |
||
| webRequest.Headers.Set(HttpRequestHeader.Authorization, $"Bearer {token}"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.