Skip to content

PoC SSO - Keycloak integration#7

Merged
GermanBluefox merged 2 commits intomainfrom
keycloak
Jun 16, 2025
Merged

PoC SSO - Keycloak integration#7
GermanBluefox merged 2 commits intomainfrom
keycloak

Conversation

@foxriver76
Copy link
Collaborator

* Get user.
*/
getUser = async (username: string, password: string): Promise<User | Falsey> => {
if (password === SSO_PASSWORD) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found a clean solution while sticking to the oauth2-server module, hence I used this approach which I don't think is perfect at all.

}

/** Keycloak ioBroker realm */
const KEYCLOAK_ISSUER = 'https://keycloak.heusinger-it.duckdns.org/realms/iobroker-local';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course after the PoC this should be a production instance hosted on public iobroker.net domain. And then other services could use the Keycloak instance too, like Cloud or Forum users. Inside of the Keycloak also other sign-ins could be configured (rn it's just GH or use normal email & pass), like Google, Apple to name the most important ones.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a proof-of-concept for SSO integration with Keycloak.

  • Adds utility functions and a constant for SSO authentication.
  • Introduces new endpoints (/sso and /sso-callback) to integrate with Keycloak's OAuth2 flow.
  • Updates the OAuth2 model and package.json to include new JWT and JWKS dependencies.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

File Description
src/lib/utils.ts Introduces SSO_PASSWORD constant and oauthTokenToResponse helper.
src/lib/oauth2.ts Adds new SSO endpoints, JWT verification, and token exchange logic.
src/lib/oauth2-model.ts Updates getUser logic to support SSO login and logs SSO attempts.
package.json Adds jsonwebtoken and jwks-rsa dependencies for JWT token verification.

options.app.post('/oauth/token', (req: Request, res: Response) => {
const request = new OAuthRequest(req);

if (request.body.password === SSO_PASSWORD) {
Copy link

Copilot AI May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider returning a 400 status code for client-side errors instead of a 500 error when the SSO password is used on a standard login request. A 400 level code will better communicate that the issue originates from an incorrect client request.

Copilot uses AI. Check for mistakes.
@foxriver76 foxriver76 marked this pull request as ready for review June 16, 2025 07:06
@GermanBluefox GermanBluefox merged commit b90bc15 into main Jun 16, 2025
6 checks passed
@GermanBluefox GermanBluefox deleted the keycloak branch June 16, 2025 10:45
GermanBluefox added a commit to ioBroker/ioBroker.admin that referenced this pull request Jun 17, 2025
this needs ioBroker/webserver#7

---------

Co-authored-by: GermanBluefox <dogafox@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants