OAuth2 Authentication
This page provides more information about the OAuth2 authentication plugin.
The plugin can be used to authenticate FileRun users against a remote server via the OAuth 2.0 protocol.
If you are new to OAuth2, here is a good introduction: https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2
You can also check out this article for more in-depth information: https://aaronparecki.com/oauth-2-simplified/
Using the plugin, FileRun acts as an OAuth2 client, utilizing the Authorization Code grant type to verify the user's identities and retrieve basic information, using to automatically create the FileRun account.
Setup
Step 1: Register the client with the OAuth2 server
Before you can begin the OAuth2 process, you must first register a new
OAuth2 client (also known as app or application) with the OAuth2
server.
When registering a new client, you usually register basic information such as application name, website, a logo, etc.
The redirect URI
In addition, you must register a redirect URI to be used for redirecting
users back to FileRun. You can retrieve the correct URI from FileRun's
control panel. It is shown in the Redirect URL field of the window of the authentication
source, after you select OAuth2 in the Plugin list (see step 2). The button next to the field
copies the address.
Important
OAuth2 servers require an HTTPS redirect URI, so your web server needs to be configured with an SSL certificate. Unsecured HTTP connections will be refused, as it represents a serious security vulnerability. Get a free SSL certificate here: https://letsencrypt.org
Step 2: Configure the FileRun plugin
You need the Client ID (sometimes referred to as app id or app key) and the Client Secret
that the OAuth2 server gave you at the step above. Open FileRun's control panel and go to
Security → Authentication.
FileRun connects to the OAuth2 server through an authentication source. Under
Authentication sources, click Add, and select OAuth2 in the Plugin list. The fields of the
plugin are in the OAuth2 plugin options part of the window. For the settings that every source
has, such as Role of new user accounts, see
Authentication integration.
The following fields will be filled with information you get from the
OAuth2 server provider: Client ID, Client Secret,
Authorization URL, Access Token URL.
The field User info HTTP method can take two possible values POST or
GET. The correct value (HTTP method) can be found in the OAuth2 server
provider's API documentation.
The List of scopes is a list of scopes, as defined by the remote API
provider, that might be required for retrieving the user's information.
The appropriate values can be found in the OAuth2 server provider's API
documentation. Separate several scopes with the character set in
Scopes separator character, which is a space by default.
Note
FileRun does not refresh access tokens. It uses the token only to read the user's details at sign-in and to create or update the FileRun account, so a short-lived token is not a problem.
The mapping fields
After the user's consent and confirming the user's identity, FileRun
will retrieve the user's basic information, in order to create a local
user account. The mandatory fields are Username mapping and
First name mapping.
FileRun will call the configured User info API URL, which in most
cases, returns a JSON object with information about the authenticated
user account.
In order to pick the correct data and map it to the FileRun fields, JSONPath selectors are being used.
Here's an example JSON output (taken from the Dropbox API):
1{
2 "account_id": "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc",
3 "name": {
4 "given_name": "Franz",
5 "surname": "Ferdinand",
6 "familiar_name": "Franz",
7 "display_name": "Franz Ferdinand (Personal)",
8 "abbreviated_name": "FF"
9 },
10 "email": "franz@dropbox.com",
11 "email_verified": true,
12 "disabled": false,
13 "locale": "en",
14 "referral_link": "https://db.tt/ZITNuhtI",
15 "country": "US"
16}
In order to map the data from name → given_name to the FileRun
First name field, you'll be using the JSONPath selector
\$.name.given_name. Let's break that down:
Root object ($)
Returns the value of the whole object.
1"$" // {account_id: "[...]", { name: { [...] }} [...] }
Property
Returns the whole value of the name property on the root object.
1"$.name" // { name: {"given_name": "Franz", [...] } }
Nested property
Returns the value of given_name on the name property of the root
object.
1"$.name.given_name" // "Franz"
Step 3: Testing
After typing in the configuration parameters, make sure that the Enabled checkbox of the source
is selected, and click Save. The test link works only while the source is enabled.
Then select the source in the list of sources and click Test. The test window shows a link to
test out the OAuth2 server's authorization process. We strongly recommend you to right-click the
link and open it in a new "private"/"incognito" browser window, so that it does not interfere
with your current FileRun session.
If the configuration is correct, you will be presented either with a login page or a consent page from the remote server.
If you proceed with the confirmation/consent, you should be redirected to FileRun, where you should find yourself signed in.
While you test, you can limit the source to your own IP address with its IP address limitation
option. The other users then do not see its button on the sign-in page.
Tip
Keep the FileRun option
Allow local user accounts to log inenabled until you are sure that everything works, so that the other local user accounts can still sign in with their passwords. The superuser can always sign in with the local password, also when this option is disabled.
Additional Notes
When the FileRun option Allow local user accounts to log in is disabled, FileRun does not send
the users to the OAuth2 server by itself. The sign-in page shows the button of the source, and the
users click it to sign in. After signing out, the users see the sign-in page again, or the address
in Redirect URL after logout, when that option is set.
Logging out will clear the OAuth2 access token from the user's
session, which means the user will be shown the OAuth2 consent page next
time he logs in. For a better user experience, it is recommended to
either enable the FileRun setting Hide the logout option or
configure Logout URL with the logout URL used by the remote system so
that the user actually logs from there and not just from FileRun.