Add support for authenticated requests
- Add optional authentication to webclient. - Update documentation accordingly. - Closes nanoframework/Home#1196.
This commit is contained in:
Родитель
73dc820c44
Коммит
5dfb319e4a
10
README.md
10
README.md
|
@ -18,6 +18,16 @@ Install .NET **nanoFramework** build components as part of a GitHub Action build
|
|||
- uses: nanoframework/nanobuild@v1
|
||||
```
|
||||
|
||||
### Authenticated usage
|
||||
|
||||
Request to GitHub API to retrieve the version information can be authenticated by adding the `gitHubAuth` and passing a GitHub Personal Access Token as a environment variable. This can be used for example if there is the need to perform authenticated requests or to keep the API usage rate under control. In this case, it will look like this:
|
||||
|
||||
```yaml
|
||||
- uses: nanoframework/nanobuild@v1
|
||||
env:
|
||||
GITHUB_AUTH_TOKEN: ${{ secrets.githubAuth }}
|
||||
```
|
||||
|
||||
## Feedback and documentation
|
||||
|
||||
For documentation, providing feedback, issues and finding out how to contribute please refer to the [Home repo](https://github.com/nanoframework/Home).
|
||||
|
|
|
@ -9,3 +9,8 @@ runs:
|
|||
steps:
|
||||
- run: '& $env:GITHUB_ACTION_PATH/install-nf-build-components.ps1'
|
||||
shell: pwsh
|
||||
inputs:
|
||||
gitHubAuth:
|
||||
required: false
|
||||
description: 'GitHub Personal Access Token for accessing GitHub API.'
|
||||
default: ''
|
||||
|
|
|
@ -21,6 +21,15 @@ $tempDir = $env:RUNNER_TEMP
|
|||
$webClient.Headers.Add("User-Agent", "request")
|
||||
$webClient.Headers.Add("Accept", "application/vnd.github.v3+json")
|
||||
|
||||
if($env:GITHUB_AUTH_TOKEN)
|
||||
{
|
||||
Write-Output "INFO: adding authentication header"
|
||||
|
||||
$auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$env:GITHUB_AUTH_TOKEN"))))"
|
||||
|
||||
$webClient.Headers.Add("Authorization", $auth)
|
||||
}
|
||||
|
||||
$releaseList = $webClient.DownloadString('https://api.github.com/repos/nanoframework/nf-Visual-Studio-extension/releases?per_page=100')
|
||||
|
||||
if($releaseList -match '\"(?<VS2022_version>v2022\.\d+\.\d+\.\d+)\"')
|
||||
|
|
Загрузка…
Ссылка в новой задаче