Skip to content

Commit 3893d8b

Browse files
committed
Automatic detection of Identity Provider or webID in login screen. Fixes #67.
1 parent 5bb6548 commit 3893d8b

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313

1414
- For logged in users not having a username, the webID is displayed (#133).
15+
- Automatic detection of Identity Provider or webID in login screen (#67).
1516

1617
### Fixed
1718

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ The static build appears in the `dist` folder.
7070

7171
## Logging in
7272

73-
Some queries access data sources that are only readable by authenticated users. This requires you to log in.
73+
Some queries access data sources that are only readable by authenticated users. This requires you to log in.
7474
To log in, you need to provide an Identity Provider or a WebID.
7575
The application will detect which one you use and redirect you to the login page of your Identity Provider.
76-
If you use your WebID, the first OIDC issuer on your WebID is used when there are multiple.
76+
If you use your WebID, the first Identity Provider found in the given WebID is used.
7777

7878
## Configuration file
7979

cypress/e2e/log-in.cy.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ describe("Log in", () => {
55
cy.get('[aria-label="Profile"]').click();
66
cy.contains('[role="menuitem"]', "Login").click();
77

8-
cy.get('input[value="webId"]').click();
9-
108
cy.get('input[name="idp"]')
119
.clear();
1210
cy.get('input[name="idp"]')
1311
.type("http://localhost:8080/example2/profile/card#me");
1412
cy.contains("Login").click();
1513

16-
cy.contains("No IDP found");
14+
cy.contains("Login failed");
1715
});
1816

1917
it("Log in with invalid WebID document", () => {
@@ -22,15 +20,33 @@ describe("Log in", () => {
2220
cy.get('[aria-label="Profile"]').click();
2321
cy.contains('[role="menuitem"]', "Login").click();
2422

25-
cy.get('input[value="webId"]').click();
26-
2723
cy.get('input[name="idp"]')
2824
.clear();
2925
cy.get('input[name="idp"]')
3026
.type("http://localhost:8080/invalidWebId/profile/card#me");
3127
cy.contains("Login").click();
3228

33-
cy.contains("Couldn't query the Identity Provider from the WebID");
29+
cy.contains("Login failed");
30+
});
31+
32+
it("Log in with WebID with OIDC issuer", () => {
33+
cy.visit("/");
34+
35+
cy.get('[aria-label="Profile"]').click();
36+
cy.contains('[role="menuitem"]', "Login").click();
37+
38+
cy.get('input[name="idp"]')
39+
.clear();
40+
cy.get('input[name="idp"]')
41+
.type("http://localhost:8080/example/profile/card#me");
42+
cy.contains("Login").click();
43+
44+
cy.get("input#email").type("hello@example.com");
45+
cy.get("input#password").type("abc123");
46+
cy.contains("button", "Log in").click();
47+
cy.contains("button", "Authorize").click();
48+
49+
cy.url().should("eq", "http://localhost:5173/");
3450
});
3551

3652
it("Log in with an invalid IDP issuer", () => {
@@ -48,7 +64,7 @@ describe("Log in", () => {
4864
cy.contains("Login failed");
4965
});
5066

51-
it("Log in and execute query on private data, then log out", () => {
67+
it("Log in with a valid IDP issuer and execute query on private data, then log out", () => {
5268
cy.visit("/");
5369

5470
cy.get('[aria-label="Profile"]').click();

src/authenticationProvider/authenticationProvider.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,21 @@ import SparqlDataProvider from "./../dataProvider/SparqlDataProvider";
1212
const queryEngine = new QueryEngine();
1313

1414
export default {
15-
login: async function login({ type, value }) {
15+
login: async function login({ value }) {
1616
const session = getDefaultSession();
1717
let idp;
18-
if (type !== "idp") {
19-
try {
20-
idp = await queryIDPfromWebId(value);
21-
} catch (error) {
22-
// Nothing to do here, the input `idpOrWebId` might be an IDP already
23-
throw new Error("Couldn't query the Identity Provider from the WebID");
24-
}
25-
}
26-
else{
27-
idp = value;
18+
19+
try {
20+
// assume it is a WebID
21+
idp = await queryIDPfromWebId(value);
22+
} catch (error) {
23+
// continue anyway, value may be an IDP
2824
}
2925

3026
if (!idp) {
31-
throw new Error("No IDP found");
27+
// value couldn't be queried or there was no IDP returned from the query
28+
// value can be an IDP
29+
idp = value;
3230
}
3331

3432
try {

src/components/LoginPage/LoginPage.jsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import configManager from "../../configManager/configManager";
1010
function SolidLoginForm() {
1111
const login = useLogin();
1212
const notify = useNotify();
13-
const [isIdp, setIsIdp] = useState(true);
1413

1514
/**
1615
* Handling what should happen when the user is trying to log in by pressing the log in button.
@@ -19,7 +18,7 @@ function SolidLoginForm() {
1918
async function handleLogin(event) {
2019
event.preventDefault();
2120
try {
22-
await login({ type: isIdp ? "idp" : "webId", value: event.target[2].value });
21+
await login({ value: event.target[0].value });
2322
} catch (error) {
2423
notify(error.message);
2524
}
@@ -29,16 +28,6 @@ function SolidLoginForm() {
2928

3029
return (
3130
<form onSubmit={handleLogin} className="login-form">
32-
<div className="login-form-type-selection-box">
33-
<label className=".login-form-label">
34-
Identity Provider
35-
</label>
36-
<input type="radio" onChange={() => {setIsIdp(!isIdp)}} name="idpOrWebId" value="idp" defaultChecked="checked"/>
37-
<label className=".login-form-label">
38-
WebID
39-
</label>
40-
<input type="radio" onChange={() => {setIsIdp(!isIdp)}} name="idpOrWebId" value="webId" />
41-
</div>
4231
<input
4332
required
4433
name="idp"

0 commit comments

Comments
 (0)