If this is a feature request, request here instead. Feature requests will be deleted from Github.
It's been discussed there as https://feats.kavitareader.com/posts/23/alternative-account-provider but I'd like to take a shot at an actual implementation, which is why I'm posting here.
The pitch:
OIDC is an open security standard that allows applications to offload the task of identity management and validation. There are large companies that implement OIDC, such as Microsoft and Google and Facebook and Discord, there are companies that provide identity management as a service like Okta, and there are self-hosted options like Keycloak and Authentik. Rather than implement an identity management interface ourselves (eg LDAP), OIDC is a light-weight standard in terms of code changes for Kavita. It also allows users/administrators to create more robust authentication mechanisms like MFA that Kavita's built-in user authentication system does not support, or to integrate with their existing communities eg manga discussion discords. This would also give us feature parity for Komga.
Implementation thoughts
This is my first time proposing a new feature for this project, and I'm doing my best to follow the guidelines outlined in CONTRIBUTING.md. I'm very open to constructive feedback. I have my local dev environment set up, but I have not started working on the changes because I want to check the approach with you all first. It sounds like opening an issue is the right way to do that rather than doing work and then opening a PR.
OIDC is an open standard with a single URL the client can use to request all of the necessary authentication endpoint URLs. The general flow would be that the user clicks "Sign in with SSO" option presented at login, the user is redirected to the identity provider (IdP) and completes the appropriate login process if necessary (may be skipped if user is already logged in, for example), the user is redirected back to Kavita with an authentication code. Kavita on the backend makes a request to the IdP to exchange the code for information about the user, such as preferred username and email address. Kavita would then use that information to see if an existing user matches that information and logs them in, or creates a new account if there's no match.
Minimum configuration for Kavita would include the metadata endpoint, the client id, and the client secret. Optional configuration would include a user-friendly name of the IdP they'll be redirected to, and an option to disable the built-in authentication system so that only OIDC authentication will be possible. We may also need options to map values in the OIDC response to Kavita fields, for example an OIDC provider might use preferredName instead of displayName for the user.
My thought about these config options is that they should be set via environment variables since this would be something to configure before the first admin user is created. Putting it in the web interface admin section would mean requiring at least one non-OIDC admin user. However, I don't know of any other options beyond timezone that Kavita currently configures this way. Open to suggestions there.
For the UI, we'd need to disable the user's ability to change password (since the IdP manages that). We'd need to remove the password reset and forgot passwords flows for the same reason. Optionally, we could instead let the admin set a URL to take users to to complete those operations. The initial admin account creation, user creation, and login processes on the UI would need to respect the OIDC configuration options presented by the API. If the user selects to login or register via the IdP, the UI should redirect to the IdP, and should pass the returned authorization code to the API to complete the login or registration process. We'd need to handle a variety of error conditions regarding that flow, plus API responses about conflicts with OIDC-specified users that already exist as non-OIDC users.
On the API side, we'd need an endpoint to return the OIDC settings, endpoint to login via OIDC, endpoint to register via OIDC. We'd need to modify the User model to indicate whether the user is a native Kavita user or an OIDC user (to prevent OIDC users impersonating native Kavita users). We'd need to get the OIDC settings out of the environment. We'd need to store the OIDC partial login state. And we'd need code to talk to the IdP to complete the authorization code->user details conversion.
I think that's about as far into the weeds as I'd want to get at the moment. Am I on the right track here? It looks like it'd be a popular feature based on the voting, and
If this is a feature request, request here instead. Feature requests will be deleted from Github.
It's been discussed there as https://feats.kavitareader.com/posts/23/alternative-account-provider but I'd like to take a shot at an actual implementation, which is why I'm posting here.
The pitch:
OIDC is an open security standard that allows applications to offload the task of identity management and validation. There are large companies that implement OIDC, such as Microsoft and Google and Facebook and Discord, there are companies that provide identity management as a service like Okta, and there are self-hosted options like Keycloak and Authentik. Rather than implement an identity management interface ourselves (eg LDAP), OIDC is a light-weight standard in terms of code changes for Kavita. It also allows users/administrators to create more robust authentication mechanisms like MFA that Kavita's built-in user authentication system does not support, or to integrate with their existing communities eg manga discussion discords. This would also give us feature parity for Komga.
Implementation thoughts
This is my first time proposing a new feature for this project, and I'm doing my best to follow the guidelines outlined in CONTRIBUTING.md. I'm very open to constructive feedback. I have my local dev environment set up, but I have not started working on the changes because I want to check the approach with you all first. It sounds like opening an issue is the right way to do that rather than doing work and then opening a PR.
OIDC is an open standard with a single URL the client can use to request all of the necessary authentication endpoint URLs. The general flow would be that the user clicks "Sign in with SSO" option presented at login, the user is redirected to the identity provider (IdP) and completes the appropriate login process if necessary (may be skipped if user is already logged in, for example), the user is redirected back to Kavita with an authentication code. Kavita on the backend makes a request to the IdP to exchange the code for information about the user, such as preferred username and email address. Kavita would then use that information to see if an existing user matches that information and logs them in, or creates a new account if there's no match.
Minimum configuration for Kavita would include the metadata endpoint, the client id, and the client secret. Optional configuration would include a user-friendly name of the IdP they'll be redirected to, and an option to disable the built-in authentication system so that only OIDC authentication will be possible. We may also need options to map values in the OIDC response to Kavita fields, for example an OIDC provider might use preferredName instead of displayName for the user.
My thought about these config options is that they should be set via environment variables since this would be something to configure before the first admin user is created. Putting it in the web interface admin section would mean requiring at least one non-OIDC admin user. However, I don't know of any other options beyond timezone that Kavita currently configures this way. Open to suggestions there.
For the UI, we'd need to disable the user's ability to change password (since the IdP manages that). We'd need to remove the password reset and forgot passwords flows for the same reason. Optionally, we could instead let the admin set a URL to take users to to complete those operations. The initial admin account creation, user creation, and login processes on the UI would need to respect the OIDC configuration options presented by the API. If the user selects to login or register via the IdP, the UI should redirect to the IdP, and should pass the returned authorization code to the API to complete the login or registration process. We'd need to handle a variety of error conditions regarding that flow, plus API responses about conflicts with OIDC-specified users that already exist as non-OIDC users.
On the API side, we'd need an endpoint to return the OIDC settings, endpoint to login via OIDC, endpoint to register via OIDC. We'd need to modify the User model to indicate whether the user is a native Kavita user or an OIDC user (to prevent OIDC users impersonating native Kavita users). We'd need to get the OIDC settings out of the environment. We'd need to store the OIDC partial login state. And we'd need code to talk to the IdP to complete the authorization code->user details conversion.
I think that's about as far into the weeds as I'd want to get at the moment. Am I on the right track here? It looks like it'd be a popular feature based on the voting, and