Sign in with NobleID on Moodle
Add Sign in with NobleID to a Moodle site as a custom OAuth 2 service.
- Written for
- Moodle 4.5 LTS and 5.0 to 5.3. The OAuth 2 screens have not changed in this range.
- Tested
- Written from the platform's documentation and source code. Not yet run against NobleID.
Register on NobleID
- In Dashboard β OAuth apps, register a confidential app. You need two-step login on your NobleID to do this.
- Add this redirect URI, with your own host:Your
https://moodle.example.org/admin/oauth2callback.php$CFG->wwwrootfollowed by/admin/oauth2callback.php. Tick ORCID iD too if you will map it. - Tick these scopes: OpenID (always on), Profile
profile, Emailemail. The platform asks for these, and sign-in stops if it asks for a scope the app does not have. - Copy the client ID and the client secret. The secret is shown once.
The app works at once. Until NobleID verifies it, people see a βnot verifiedβ notice on the consent screen.
How Moodle's OAuth 2 login behaves
- It reads NobleID's discovery document from the Service base URL and creates the endpoints itself.
- It reads the person from the userinfo endpoint and does not use the ID token, so ES256 needs no setting.
- It sends
state. It sends no PKCE ornonce, and has no PKCE option. - It needs a username and an email from userinfo. A person who unticks
emailcannot sign in. - It cannot read
email_verified. Its own Require email verification option is the safeguard: keep it on. - Signing out is local.
1. Create the service
Site administration β Server β OAuth 2 services β Create new service: Custom.
| Field | Value |
|---|---|
| Name | NobleID |
| Client ID | nbcl_your_client_id |
| Client secret | nbcs_your_client_secret |
| Authenticate token requests via HTTP headers | your choice (NobleID accepts both) |
| Service base URL | https://id.nobleid.org (Moodle adds /.well-known/openid-configuration) |
| This service will be used | Login page only |
| Name displayed on the login page | Sign in with NobleID |
| Scopes included in a login request | openid profile email |
| Scopes included in a login request for offline access | leave empty |
| Additional parameters (both fields) | leave empty |
| Login domains | leave empty, or limit to your institution's email domains |
| Require email verification | on |
Save. The services list should show discovery as successful.
2. Check the endpoints
Click Configure endpoints for the service. Discovery should have created at least:
| Name | URL |
|---|---|
authorization_endpoint | https://www.nobleid.org/oauth/authorize |
token_endpoint | https://id.nobleid.org/oauth/token |
userinfo_endpoint | https://id.nobleid.org/oauth/userinfo |
3. Map the account to sub
Click Configure user field mappings. Discovery creates mappings for given_name, family_name, email and picture, and a few claims NobleID does not send. Add one more:
| External field name | Internal field name |
|---|---|
sub | username |
Without it, Moodle links the NobleID login to the email address, and a person who changes their NobleID email loses the link. With it, the link uses sub, which never changes.
Optional: add orcid to the login scopes and map orcid to a custom profile field.
4. Turn on the plugin
Site administration β Plugins β Authentication β Manage authentication β enable OAuth 2. The Sign in with NobleID button then appears on the login page.
With Require email verification on, Moodle emails a confirmation link before it connects a NobleID login to an existing account with the same email, and new accounts confirm their email before first use. Keep it on: Moodle cannot see whether NobleID confirmed the address.
Fill the profile from NobleID
| NobleID claim | Moodle field | Scope |
|---|---|---|
given_name | firstname | profile |
family_name | lastname | profile |
email | email | email |
picture | picture | profile |
orcid | a text custom profile field (optional) | orcid |
Discovery creates the first four mappings (step 3).
For the ORCID iD: create a text custom profile field, add orcid to the service's login scopes, tick ORCID iD on your app, and map orcid to the field.
Every claim, and how to fill a profile without overwriting what people edit: Fill your app's profile from NobleID.
Before you go live
- Sign in once with your own NobleID. People need a first and last name on their NobleID profile to sign in; NobleID asks for it if it is missing.
- Key accounts on
sub. Link to an existing account by email only whenemail_verifiedis true. - Remove any localhost redirect URIs from the app.
- Keep the client secret out of version control.
NobleID values
| Issuer | https://id.nobleid.org |
| Discovery URL | https://id.nobleid.org/.well-known/openid-configuration |
| Authorization endpoint | https://www.nobleid.org/oauth/authorize |
| Token endpoint | https://id.nobleid.org/oauth/token |
| Userinfo endpoint | https://id.nobleid.org/oauth/userinfo |
| JWKS URL | https://id.nobleid.org/.well-known/jwks.json |
| Revocation endpoint | https://id.nobleid.org/oauth/revoke |
| End-session endpoint | https://www.nobleid.org/oauth/logout |
| ID token signing | ES256 |
Sources
Something here does not match what you see? Email info@nobleid.org.