Add support for authenticated requests

- Add optional authentication to webclient.
- Update documentation accordingly.
- Closes nanoframework/Home#1196.
This commit is contained in:
José Simões 2022-12-20 09:03:19 +00:00
Родитель 73dc820c44
Коммит 5dfb319e4a
3 изменённых файлов: 24 добавлений и 0 удалений

Просмотреть файл

@ -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+)\"')