Skip to content

Commit d27b275

Browse files
committed
Add support for bearer token authentication
This sets the `Authorization: Bearer [token]` header in upstream proxy requests, allowing for mirrors of e.g. GitLab.
1 parent cdfacbb commit d27b275

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

.env.dist

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ VELOCITA_HTTPS_PORT=8443
1111
#VELOCITA_AUTH_TYPE=none
1212

1313
##
14-
# GitHub mirror configuration
14+
# Mirrors configuration
1515
##
1616

17+
# GitHub codeload
1718
MIRROR_GITHUB_CODELOAD_URL=https://codeload.github.com
1819
#MIRROR_GITHUB_CODELOAD_CACHE_SIZE=1g
1920

20-
##
21-
# Composer repository mirrors
22-
##
23-
21+
# Packagist
2422
MIRROR_PACKAGIST_URL=https://repo.packagist.org
2523
MIRROR_PACKAGIST_TYPE=composer
2624
#MIRROR_PACKAGIST_CACHE_EXPIRY=3650d
@@ -31,3 +29,9 @@ MIRROR_PACKAGIST_TYPE=composer
3129
#MIRROR_PACKAGIST_AUTH_USERNAME=
3230
#MIRROR_PACKAGIST_AUTH_PASSWORD=
3331
#MIRROR_PACKAGIST_USER_AGENT=Velocita Composer Cache
32+
33+
# GitLab (example)
34+
#MIRROR_GITLAB_URL=https://gitlab.com
35+
#MIRROR_GITLAB_TYPE=composer
36+
#MIRROR_GITLAB_AUTH_TYPE=bearer
37+
#MIRROR_GITLAB_AUTH_PASSWORD=...

proxy/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ For every mirror, the following configuration options are available:
5959
| `MIRROR_{name}_CACHE_SIZE` | No | Size (default: `1g`) | Maximum size of this mirror's cache |
6060
| `MIRROR_{name}_ALLOW_REVALIDATE` | No | Boolean (default: `false`) | Allow revalidation of cached items |
6161
| `MIRROR_{name}_PACKAGES_JSON_EXPIRY` | No | Time (default: `2m`) | Time after which `packages.json` expires |
62-
| `MIRROR_{name}_AUTH_TYPE` | No | Always `basic` (default) | Type of upstream authentication |
63-
| `MIRROR_{name}_AUTH_USERNAME` | No | String | Username for basic authentication |
64-
| `MIRROR_{name}_AUTH_PASSWORD` | No | String | Password for basic authentication |
62+
| `MIRROR_{name}_AUTH_TYPE` | No | One of: `basic` (default), `bearer` | Type of upstream authentication |
63+
| `MIRROR_{name}_AUTH_USERNAME` | No | String | Username for authentication |
64+
| `MIRROR_{name}_AUTH_PASSWORD` | No | String | Password or token for authentication |
6565
| `MIRROR_{name}_USER_AGENT` | No | String | User Agent header sent to upstream |
6666

6767
For time and size unit syntax, see: http://nginx.org/en/docs/syntax.html

proxy/templates/proxy.conf.erb

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ server {
147147
<%- unless mirror[:auth_user].empty? || mirror[:auth_pass].empty? -%>
148148
proxy_set_header Authorization "Basic <%= Base64.strict_encode64("#{mirror[:auth_user]}:#{mirror[:auth_pass]}") %>";
149149
<%- end -%>
150+
<%- when 'bearer' -%>
151+
<%- unless mirror[:auth_pass].empty? -%>
152+
proxy_set_header Authorization "Bearer <%= mirror[:auth_pass] %>";
153+
<%- end -%>
150154
<%- end -%>
151155
<%- if mirror[:type] == 'composer' -%>
152156

0 commit comments

Comments
 (0)