|
| 1 | +## Built-in HTTP Authentication |
| 2 | + |
| 3 | +This page applies to inlets-pro 0.10.0 and onwards. |
| 4 | + |
| 5 | +Services exposed over HTTP tunnels can have additional authentication added to them using a mechanism built-into inlets. |
| 6 | + |
| 7 | +The `inlets-pro http` command provides three options: |
| 8 | + |
| 9 | +1. Basic Authentication |
| 10 | +2. Bearer Token Authentication |
| 11 | +3. OAuth |
| 12 | + |
| 13 | +## Basic Authentication |
| 14 | + |
| 15 | +Basic authentication is a simple way to restrict access to your service by requiring a username and password. |
| 16 | + |
| 17 | +When a user visits the URL of the service in a web-browser, they will be prompted to enter a username and password. |
| 18 | + |
| 19 | +If they're using curl, then they can pass the username and password using the `--user` flag. |
| 20 | + |
| 21 | +```bash |
| 22 | +curl --user username:password https://example.com |
| 23 | +``` |
| 24 | + |
| 25 | +Or simply pass the username and password as part of the URL: |
| 26 | + |
| 27 | +```bash |
| 28 | +curl https://username: [email protected] |
| 29 | +``` |
| 30 | + |
| 31 | +The username has a default of `admin` for brevity, but can be overridden if you like: |
| 32 | + |
| 33 | +```bash |
| 34 | +inlets-pro http client \ |
| 35 | + --basic-auth-username admin \ |
| 36 | + --basic-auth-password password \ |
| 37 | +``` |
| 38 | + |
| 39 | +You can generate a string password using the `openssl` command: |
| 40 | + |
| 41 | +```bash |
| 42 | +openssl rand -base64 32 |
| 43 | +``` |
| 44 | + |
| 45 | +## Bearer Token Authentication |
| 46 | + |
| 47 | +If you're exposing an endpoint that does not need to be accessed via a web-browser, then you can use Bearer Token Authentication. |
| 48 | + |
| 49 | +This is useful for exposing endpoints that are used by mobile apps or other non-web clients. |
| 50 | + |
| 51 | +To enable Bearer Token Authentication, you can use the `--bearer-token` flag when starting the `inlets-pro http` command. |
| 52 | + |
| 53 | +```bash |
| 54 | +inlets-pro http client \ |
| 55 | + --bearer-token token \ |
| 56 | +``` |
| 57 | + |
| 58 | +Both Bearer Token and Basic Authentication can be used together by supplying both flags. |
| 59 | + |
| 60 | +```bash |
| 61 | +inlets-pro http client \ |
| 62 | + --bearer-token token \ |
| 63 | + --basic-auth-username admin \ |
| 64 | + --basic-auth-password password \ |
| 65 | +``` |
| 66 | + |
| 67 | +## OAuth |
| 68 | + |
| 69 | +With OAuth: |
| 70 | + |
| 71 | +* You can define access for multiple users using usernames or email addresses |
| 72 | +* Avoid managing credentials in your application |
| 73 | +* Use an existing well-known provider for authentication such as GitHub |
| 74 | + |
| 75 | +The OAuth 2.0 flow requires a web-browser, so if you anticipate mixed use, then you can combine it with Bearer Token Authentication, for headless clients. |
| 76 | + |
| 77 | +### Example with GitHub.com |
| 78 | + |
| 79 | +The example below will expose: `http://127.0.0.1:3000` using the domain name `tunnel.example.com`. |
| 80 | + |
| 81 | +In order to use GitHub as the OAuth provider, you need to create a new OAuth application. |
| 82 | + |
| 83 | +1. Go to [GitHub Developer Settings](https://github.com/settings/developers) |
| 84 | +2. Click on "New OAuth App" |
| 85 | +3. Enter a name for the application, for example `inlets-tunnel` |
| 86 | +4. Enter the callback URL, for example `http://tunnel.example.com/_/oauth/callback` |
| 87 | +5. Click on "Register application" |
| 88 | +6. Click "Generate a new client secret" |
| 89 | + |
| 90 | +You will be given a client ID and client secret, which you can use to authenticate with GitHub. |
| 91 | + |
| 92 | +We suggest saving this in a convenient location, for example: `~/.inlets/oauth-client-id` and `~/.inlets/oauth-client-secret`. |
| 93 | + |
| 94 | +```bash |
| 95 | +inlets-pro http client \ |
| 96 | + --oauth-client-id $(cat ~/.inlets/oauth-client-id) \ |
| 97 | + --oauth-client-secret $(cat ~/.inlets/oauth-client-secret) \ |
| 98 | + --upstream tunnel.example.com=http://127.0.0.1:3000 \ |
| 99 | + --oauth-provider github \ |
| 100 | + --oauth-acl alexellis \ |
| 101 | + |
| 102 | +``` |
| 103 | + |
| 104 | +Once authenticated, a cookie will be set on the domain i.e. `tunnel.example.com` and the user will be redirected back to the root URL of the service `/`. |
| 105 | + |
| 106 | +The duration of the cookie defaults to 5 minutes, but can be extended. |
| 107 | + |
| 108 | +For the first version, GitHub is the only option available for the `--oauth-provider`. More options will be added over time, based upon requests from users, so if you want to use Google, Facebook, GitLab, etc, send us an email to help with prioritisation. |
| 109 | + |
| 110 | + |
0 commit comments