Skip to content
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

Add OIDC #374

Merged
merged 16 commits into from
Jul 15, 2023
Merged

Add OIDC #374

merged 16 commits into from
Jul 15, 2023

Conversation

trueChazza
Copy link
Member

Add OIDC

@trueChazza trueChazza self-assigned this Jun 27, 2023
@trueChazza trueChazza mentioned this pull request Jun 27, 2023
@trueChazza
Copy link
Member Author

@onedr0p I've just started with GitHub provider for now to flesh out the approach - then I'll adjust to suit generic identity provider i.e. Authelia, Authentik etc

@trueChazza trueChazza added this to the v4.0.0 milestone Jun 27, 2023
@trueChazza trueChazza linked an issue Jun 27, 2023 that may be closed by this pull request
@trueChazza trueChazza added the enhancement New feature or request label Jun 27, 2023
- OAUTH_CLIENT_SECRET=someClientSecret
- OAUTH_REDIRECT_URI=http://localhost:4000/auth/authentik/callback
- OAUTH_USER_URL=http://server-authentik:9000/application/o/userinfo/

Copy link
Member Author

Choose a reason for hiding this comment

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

@onedr0p Example environment variables for configuring oauth.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good so far.

if user = MediaServer.Accounts.get_user_by_email(get_user!(provider, client).email) do

MediaServerWeb.UserAuth.log_in_user(conn, user)
end
Copy link
Member Author

@trueChazza trueChazza Jun 28, 2023

Choose a reason for hiding this comment

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

@onedr0p

Thoughts on this? Here it gets a user registered in the Midarr database that matches the email returned by Authentik, then logs them in.

What's your take on this, and the auth flow?

If a user returned by Authentik doesn't exist in Midarr - register them, then log them in?

Copy link
Contributor

@onedr0p onedr0p Jun 28, 2023

Choose a reason for hiding this comment

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

I wouldn't auto-create users since the source of truth is the OIDC provider, meaning to say they would need to be added to the OIDC provider first and if they aren't an existing user they cannot login. Deny by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking oauth / OIDC provider would be an optional alternative, with Midarr still the source of truth for user auth. There would need to be some level of user mapping to support both options.

Copy link
Member Author

@trueChazza trueChazza Jul 2, 2023

Choose a reason for hiding this comment

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

For now just to keep moving forward - I'll go with the logic as above (user must exist in Midarr and OIDC provider to login).

We can continue to improve the flow in future iterations 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant to comment and say pretty much that. 😅

@trueChazza
Copy link
Member Author

trueChazza commented Jun 28, 2023

@onedr0p - here's a first pass build on oauth. Please give it a run through, and let me know how it goes 😄

v3.2.0-beta.2

http://midarr:4000/auth/authentik - go to this url to auth with Authentik.

OAUTH_ISSUER_URL=http://localhost:9000
OAUTH_AUTHORIZE_URL=http://localhost:9000/application/o/authorize/
OAUTH_TOKEN_URL=http://server-authentik:9000/application/o/token/
OAUTH_CLIENT_ID=someClientId
OAUTH_CLIENT_SECRET=someClientSecret
OAUTH_REDIRECT_URI=http://localhost:4000/auth/authentik/callback
OAUTH_USER_URL=http://server-authentik:9000/application/o/userinfo/

@onedr0p
Copy link
Contributor

onedr0p commented Jun 28, 2023

@trueChazza oauth is generic and doesn't matter if it is (for example) authelia/authentik, so your provider should probably be called oauth generic/custom.

Take a look at the grafana docs on how they allow people to configure this...

https://grafana.com/docs/grafana/latest/setup-grafana/configure-security/configure-authentication/generic-oauth/

Also it might be helpful to look at the docs on Authelia and see how they allow you to configure applications to use OIDC, on the left you can choose an app to see more how it is configured... e.g. BookStack or the many other examples on there like grafana

https://www.authelia.com/integration/openid-connect/introduction/

@trueChazza
Copy link
Member Author

trueChazza commented Jun 28, 2023

@trueChazza oauth is generic and doesn't matter if it is (for example) authelia/authentik, so your provider should probably be called oauth generic/custom.

Take a look at the grafana docs on how they allow people to configure this...

https://grafana.com/docs/grafana/latest/setup-grafana/configure-security/configure-authentication/generic-oauth/

Also it might be helpful to look at the docs on Authelia and see how they allow you to configure applications to use OIDC, on the left you can choose an app to see more how it is configured... e.g. BookStack or the many other examples on there like grafana

https://www.authelia.com/integration/openid-connect/introduction/

Awesome thank you for this!

@trueChazza trueChazza requested a review from onedr0p July 11, 2023 22:22
@trueChazza trueChazza marked this pull request as ready for review July 11, 2023 22:34
@trueChazza trueChazza mentioned this pull request Jul 11, 2023
@trueChazza trueChazza merged commit c15ae2b into master Jul 15, 2023
2 checks passed
@trueChazza trueChazza deleted the feature/add-oidc branch July 15, 2023 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

OIDC support
2 participants