-
Notifications
You must be signed in to change notification settings - Fork 480
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
Integrate passportjs for muti-strategy authentication and SSO #1636
Conversation
I think passportjs will be a good solution from the looks of it. It was attempted here #351 but never got finalized and then the v2 rewrite happened. @mfcar also discussed implementing this via passportjs in Discord but I don't think anything happened there. I haven't got around to checking the PR yet but wanted to follow up. |
I still need to start the work with SSO. Sorry about this. I think the @lukeIam's PR it's a very good start. |
Added passport-openidconnect implementation and tested with |
When getting the local strategy working I ran into an issue where it didn't allow an empty password to be passed in. Since that was already an allowable option and some users may be doing that I included the package in I haven't tested oauth2 yet but I just got authentik setup. |
oh, wasn't aware of that...
ok - that maintainer seems not want to have such a feature (as it's not longer an authorization).
Let me know when I can assist. {
"authActiveAuthMethods": [
"local",
"google-oauth20",
"openid"
],
"authGoogleOauth20ClientID": "[ID]apps.googleusercontent.com",
"authGoogleOauth20ClientSecret": "[SECRET]",
"authGoogleOauth20CallbackURL": "/auth/google/callback",
"authOpenIDIssuerURL": "https://[URL]/application/o/audiobookshelf/",
"authOpenIDAuthorizationURL": "https://[URL]/application/o/authorize/",
"authOpenIDTokenURL": "https://[URL]/application/o/token/",
"authOpenIDUserInfoURL": "https://[URL]/application/o/userinfo/",
"authOpenIDClientID": "[ID]",
"authOpenIDClientSecret": "[SECRET]",
"authOpenIDCallbackURL": "/auth/openid/callback"
} |
I think it's fine. The last change in that library was many years ago. All the commits I see over the last several years are documentation updates. It is also a small library so I think we are fine including this internally. |
What needs to be done before this can be implemented? |
I have not fully understood how the current socket connection is working and is authenticated. // convert a connect middleware to a Socket.IO middleware
const wrap = middleware => (socket, next) => middleware(socket.request, {}, next);
io.use(wrap(sessionMiddleware));
io.use(wrap(passport.initialize()));
io.use(wrap(passport.session())); from https://github.com/socketio/socket.io/blob/master/examples/passport-example/index.js#L75-L80 and on client side: const socket = io.connect('', {
extraHeaders: {
Authorization: "[...]",
},
}); But again I'm just guessing here... |
took a bit longer than promised here (#998 (comment)) - but I found some time to program again 😃 In the dev container I'm now able to login with google auth (openid should also work but untested). Main blocker at the moment:
Currently I'm redirecting away from the app completely and have problems finding back. Edit: maybe oauth2 state field is an option (but would only work for oauth based logins) But there is also other stuff to do:
|
Thanks, I'd like to get back into this one again. We need to merge this with master which is going to have a lot of conflicts at this point |
@advplyr I already merged in master from time to time and resolved the conflicts (but we should double check)
|
I'm currently very busy with other stuff - sorry Here is my current working stage for optional automatic user creation: If something is blocking you where I can help please let me know and I will make some time available... |
@lukeIam Main points we are discussing and testing:
So the PR is progressing fast |
…d logout URL server settings, use email and email_verified instead of username
I just made the change to openid-client That required the JWKS url so I added that to the server settings and UI. We will also need the This is getting a bit crowded and seems unnecessary since I think we can get all of that from the config url The other change I made was using the |
Co-authored-by: Denis Arnst <git@sapd.eu>
855877e
to
c17540e
Compare
…gs. Auto register user. Persist sub on User records
I added the server settings for auto-registering and matching existing users.
There are still a few details to workout.
|
Another part I keep forgetting about is applying/updating the settings to passport. Currently the settings are only applied when first starting the server, so you have to restart after updating settings. |
- Provide error handling for /auth/openid - Add session.mobile inside /auth/openid - Proper PKCE handling for /auth/openid/callback - redirect_uri handling for the token url in /auth/openid/callback Co-authored-by: Denis Arnst <git@sapd.eu>
Remove remaining google oauth server settings
This is mostly wrapped up now. I removed the google oauth stuff so we can handle that in a separate PR. Before this merges we may want to add a logout button. I'm thinking the client just stores the auth method locally and shows an additional logout button allowing the user logout of the provider. We may also want to support setting the account type of auto-registered users using a user provided claim |
To add to this. This PR as-is should work with Google out of the box, because Google simply uses OIDC. However I did not test it. So a specific Google implementation is not required. However for the mobile app a change is probably required in the app and in the backend (a small additional route), because Google is has some additional rules regarding the callback URL. I can implement that if someone needs that and the PR here was released. |
I've been doing some more testing and I think things are solid the way they are now. In separate PRs we can implement setting the account type when auto-registering and a logout button using the openid logout url. As it stands auto-registered users will be the "User" account type with default user permissions (download only). Another future update can clean up Further testing can be done on Thanks to everyone contributing on this! |
As I wrote in the SSO issue (#998 (comment)) I would suggest to integrate a well supported auth middleware instead of implementing single protocols by hand.
This PR shows a possible integration of passortjs into the server code of audiobookshelf.
Login with username + password and google oauth2 integrated and working so far. But other auth providers can be integrated really easily with a few lines of code (supported strategies).
My current implementation is not final nor ready to be merged - it is more meant as a PoC.
But if you (@advplyr and also others) decide that you want to go in this direction I'm happy to develop/contribute to a stable implementation.
I don't have a client implementation atm - I'm testing with postman...
Login via:
POST /login
for username + passwordGET /auth/google
redirects to google loginThe response returns the known json with a token but also a cookie is set containing the session.
For the further API communication either the token (Bearer header) or the cookie can be used if authentication.
Maybe the cookie simplifies the handling in the webclients of the apps.
Most of the changes where done in the
Auth.js
file - I tried to not touch the other code where possible.So what do you think? Is
passportjs
a good idea or do you prefer to go in another direction?