Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OIDC login + extra features #38

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ce4b45f
wip
pheyvaer Mar 31, 2023
07fa10f
Something that works
pheyvaer Apr 4, 2023
83c6f98
Remove unused code
pheyvaer Apr 4, 2023
1702124
Remove unused files
pheyvaer Apr 5, 2023
2c552d3
Separate code + support logout
pheyvaer Apr 5, 2023
547dda2
wip client credentials handler
pheyvaer Apr 5, 2023
3009a08
wip client credentials handler
pheyvaer Apr 5, 2023
22f35fe
Fix logout OIDC
pheyvaer Apr 5, 2023
bc192dc
Add buttons to switch between log in methods
pheyvaer Apr 5, 2023
80f4ec2
Add client name to OIDC login
pheyvaer Apr 5, 2023
4a2e7f5
return login status
pheyvaer Apr 5, 2023
b19d4f8
Put restore of session in handlers
pheyvaer Apr 5, 2023
73e77f6
Clean up
pheyvaer Apr 14, 2023
0a33c87
Show message that new tab has been opened for IDP
pheyvaer Apr 14, 2023
9a700cd
Update debug statement
pheyvaer Apr 14, 2023
ea351f1
Show latest IDP afer logging out or reloading extension
pheyvaer Apr 14, 2023
93aa3ec
Save authenticated requests to history via handler
pheyvaer Apr 17, 2023
f1e91e4
Add used WebID to history
pheyvaer Apr 17, 2023
cb47fb3
Show history in new tab
pheyvaer Apr 17, 2023
a7f1bf3
Add button to clear request history
pheyvaer Apr 18, 2023
56e1f4b
Add content script so page scripts can access status of extension
pheyvaer Apr 18, 2023
7865e3d
Add example status website
pheyvaer Apr 18, 2023
e864b85
Add listener option for window.solid
pheyvaer Apr 19, 2023
7854bec
Update README status website
pheyvaer Apr 19, 2023
ad720ca
Add onStatusChange example
pheyvaer Apr 19, 2023
f1cdae6
Add info about OIDC
pheyvaer Apr 20, 2023
7659f14
Add some styling
pheyvaer Apr 21, 2023
a30bd4a
Add option to use WebID for OIDC instead of IDP.
pheyvaer Apr 21, 2023
24a0a6c
Check isLoggedIn has been changed and call corresponding callback
pheyvaer Apr 26, 2023
dd6bf4f
Fix comment
pheyvaer Apr 26, 2023
eac8ed5
Add license
pheyvaer Apr 26, 2023
bd8d9f8
Nicer table for history
pheyvaer Apr 27, 2023
213ce88
Add hot-reloading development upgrade
rafael-mindreau Jun 7, 2023
fa80183
Merge branch 'main' into feature/oidc-login
rafael-mindreau Jun 7, 2023
6138ae3
Merge branch 'main' into feature/oidc-login
rafael-mindreau Jun 7, 2023
cb5f2ce
Hide CSS mode by default
rafael-mindreau Jun 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
}
}
91 changes: 53 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
# Solid Authentication Extension

This FireFox extension replaces unauthenticated requests with authenticated Solid requests.
This extension only works with WebIDs that use
the [Community Solid Server](https://github.com/CommunitySolidServer/CommunitySolidServer) (>= v4.0.0)
as identity provider.
You are able to log in with [OIDC](#oidc) or
[Client Credentials](#client-credentials).

You can create a Solid pod for testing via the [SolidLab Playground](https://pod.playground.solidlab.be/).

## OIDC

You are able to log in with [OIDC](https://solidproject.org/TR/oidc)
via the following steps:

1. Install the extension.
2. Click on the Solid icon in the toolbar and a popup will open.
3. Provide your identity provider in the corresponding field.
4. Click on the "Log in" button and new a tab will open.
5. Log in to your identity provider in the new tab.
6. The tab will close once you are logged in.
7. Your requests are now authenticated.

## Client Credentials

Requests are authenticated using the
[Client Credentials API](https://communitysolidserver.github.io/CommunitySolidServer/5.x/usage/client-credentials/).
You need at least v4.0.0 of the Community Solid Server for this to work.
You can only use [Client Credentials](https://communitysolidserver.github.io/CommunitySolidServer/5.x/usage/client-credentials/)
if your identify provider is the [Community Solid Server](https://github.com/CommunitySolidServer/CommunitySolidServer) (>= v4.0.0).

The extension uses temporary access tokens that are created using either
the client's email and password used on the server or
The extension uses temporary access tokens that are created using either
the client's email and password used on the server or
a previously created id and secret linked to the user's WebID on the server.

You can create a Solid pod for testing via the [SolidLab Playground](https://pod.playground.solidlab.be/).

## Development environment

- [Node.js](https://nodejs.org/en) v18.12.1
- npm v8.19.2

You find instructions on how to install Node.js and npm
You find instructions on how to install Node.js and npm
[here](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm#using-a-node-installer-to-install-nodejs-and-npm).

Tested on macOS 13.1.
Expand All @@ -31,25 +42,14 @@ Tested on macOS 13.1.

You can develop and test the by doing the following steps:

1. Install dependencies via
1. Install dependencies via
```shell
npm i
```
2. Build the extension using webpack via
2. Run the start command to fire up hot reload
```shell
npm run build
npm run build:dev
```
This places all the necessary bundled files in the newly created `dist` directory .
3. Install the [Firefox Browser Developer Edition](https://www.mozilla.org/en-US/firefox/developer/).
4. Navigate to `about:debugging#/runtime/this-firefox`.
5. Select `Load Temporary Add-on` at the top of the page.
6. When a file explorer appears, navigate tot the aforementioned `dist` directory and select the `manifest.json` file withing this directory.
Do NOT select the manifest in the working directory itself, this will cause the extension to not work.
7. The extension should now be running, both it's browser popup and the background process.

If you can't find the extension icon which opens the popup window,
it's most likely unpinned and hidden away in the extension menu which can be opened by
clicking the jigsaw icon on the top right of the browser window.

## Package

Expand All @@ -69,7 +69,7 @@ You can package the extension for distribution and signing via the following ste

If you want to use the extension with the standard edition of FireFox,
you need to use the signed version of the extension.
You find this version in assets of
You find this version in assets of
the [releases](https://github.com/KNowledgeOnWebScale/solid-authentication-browser-extension/releases).
The file ends with `.xpi`.

Expand All @@ -78,32 +78,47 @@ You find more information about how to add an extension to FireFox from a file

## Session

The extension will remember your credentials (ID & Secret combination) in your browser storage.
The following only applies to Client Credentials.

The extension will remember your credentials (ID & Secret combination) in your browser storage.
This will allow the extension to restore and reuse your previously generated id and secret after you press
`reload` in the aforementioned debugging menu until you log out manually.

Because the extension is not [signed](https://support.mozilla.org/en-US/kb/add-on-signing-in-firefox) during development,
Because the extension is not [signed](https://support.mozilla.org/en-US/kb/add-on-signing-in-firefox) during development,
it's [add-on id](https://extensionworkshop.com/documentation/develop/extensions-and-the-add-on-id/)
is not static.
Because of this,
if you remove and reload the extension or restart your browser and reload the extension,
is not static.
Because of this,
if you remove and reload the extension or restart your browser and reload the extension,
the extension won't find it's previously saved credentials in the browser storage and you will have to log in again.

## GET requests only
## GET and PUT requests only

At this time, the extension will only add authentication to GET requests.
POST requests will not be blocked, but won't have any authentication either.
At this time, the extension will only add authentication to GET and PUT requests.
POST and HEAD requests will not be blocked, but won't have any authentication either.

This is because, the (blocking) web request listener that catches any outgoing request from the browser user,
will catch any outgoing requests from the extension background script as well,
specifically POST request [requesting the token url](https://github.com/KNowledgeOnWebScale/solid-authentication-browser-extension/blob/8211dab9b7a42fa98eeef37158084788e62d251a/src/js/solid.js#L51-L60)
and [requesting access tokens from said url](https://github.com/KNowledgeOnWebScale/solid-authentication-browser-extension/blob/8211dab9b7a42fa98eeef37158084788e62d251a/src/js/solid.js#L30-L44).

To prevent an infinite loop of blocking web request listeners catching each other, any POST request that is caught,
[will be passed](https://github.com/KNowledgeOnWebScale/solid-authentication-browser-extension/blob/8211dab9b7a42fa98eeef37158084788e62d251a/src/js/background.js#L48-L50)
before any token url or access token is requested, and consequently any authentication is added.
To prevent an infinite loop of blocking web request listeners catching each other, any POST request that is caught,
[will be passed](https://github.com/KNowledgeOnWebScale/solid-authentication-browser-extension/blob/8211dab9b7a42fa98eeef37158084788e62d251a/src/js/background.js#L48-L50)
before any token url or access token is requested, and consequently any authentication is added.

## Screencast

You find a screencast of the extension [here](https://cloud.ilabt.imec.be/index.php/s/QbabTcHkX2J8GHG).
You find a screencast of the extension [here](https://cloud.ilabt.imec.be/index.php/s/QbabTcHkX2J8GHG).

## Tested servers with OIDC login

| IDP | Resource | Works? | Comments |
|-----|----------|--------|------------------------------------------------------|
| CSS | CSS | Yes | |
| ESS | ESS | Yes | |
| NSS | NSS | No | Something weird with status codes received from NSS. |
| NSS | CSS | Yes | |

## License

This code is copyrighted by [Ghent University – imec](http://idlab.ugent.be/) and
released under the [MIT license](http://opensource.org/licenses/MIT).
1 change: 1 addition & 0 deletions examples/status-website/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
61 changes: 61 additions & 0 deletions examples/status-website/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Solid Authentication extension status website

This website shows the status of the Solid Authentication browser extension.
It shows if the extension is authenticated and what the WebID is of the logged-in agent.

## Requirements

You have this [commit](https://github.com/KNowledgeOnWebScale/solid-authentication-browser-extension/commit/56e1f4badd20eeb9af9f4a53feb2571339f69dfc)
of the browser extension installed.

## Host website locally

1. Install dependencies via `npm i`.
2. Run HTTP server via `npm start`.
3. Browse to `http://localhost:8080`.

## How it works

The extension adds the property `solid` to `window` which the script of a Web page can access.
This property has two methods: `getStatus(callback)` and `onStatusChange(callback)`.

### `getStatus(callback)`
This method gets the status from the extension
and passes it **stringified** to the provided callback.
The status is an object that looks like when you are logged in:

```json
{
"authenticated": true,
"webId": "https://pod.playground.solidlab.be/ash/profile/card#me"
}
```

When you are not logged in the object is:

```json
{
"authenticated": false
}
```

In the page script you do something like:

```javascript
window.solid.getStatus(status => {
status = JSON.parse(status);
console.log(status);
});
```

### `onStatusChange(callback)`
This method registers a callback that is called everytime the status changes.
It passes the same **stringified** object as for `getStatus` to the callback.
In the page script you do something like:

```javascript
window.solid.onStatusChange(status => {
status = JSON.parse(status);
console.log(status);
});
```
27 changes: 27 additions & 0 deletions examples/status-website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Extension status website</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
This page shows the status of the Solid Authentication browser extension.<br/>
The values below change automatically when you log in or out with the extension.
</div>

<div id="error" class="hidden">
<code>window.solid</code> is undefined. Did you install the extension? <br/>
Once you do, refresh this page.
</div>
<div>
<ul>
<li>Logged in: <span id="logged-in"></span></li>
<li>WebID: <span id=webId></span></li>
</ul>
</div>

<script type="application/javascript" src="script.js"></script>
</body>
</html>
Loading