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

Allow DataEntryFlowStepExternal on the login screen #14471

Conversation

christiaangoossens
Copy link

Proposed change

Many authentication methods use external steps, such as OpenID Connect, which requests a redirect to the Identity Provider, which is then returned with a callback to the app. While there seems to be no current intention to add these types of providers to home-assistant/core, it is also not possible to create external plugins implementing these features, because the DataEntryFlowStepExternal step is not supported on the login screen (/auth/authorize) in the frontend.

This PR proposes adding this feature, such that custom components/integrations/plugins implementing these types of authentication providers can be created. Request for this from the community seems big enough to create such a plugin.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

You can use the current version of https://github.com/christiaangoossens/hass-oidc-auth, which is a minimal plugin (installed by adding it to the custom_components directory and adding auth_oidc: to the configuration yaml), that only implements a callback and a screen calling this DataEntryFlowStepExternal. If you receive a console output of "value" after completing the entire flow, the integration is successful.

Additional information

PR is heavily inspired by #5258, but this time aims to make the functionality usable in external plugins, instead of the core backend.

Currently, a very basic initial implementation was submitted to demonstrate the idea, however, I would like to find a way to make this work on Android and iOS, preferably by using the native browser, and to not use popups/new tabs on the desktop but instead redirect and redirect back. Advice on how to proceed is welcome, both from the frontend and mobile teams.

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Further steps that need to be done:

  • Code is clean and has no code duplication
  • Code works on Android Companion App
  • Code works on iOS Companion App
  • Code uses a redirect on the desktop instead of a popup (window.open)

@home-assistant
Copy link

Hi christiaangoossens

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Comment on lines +236 to +242
return html` ${this._computeStepDescription(step)
? html`
<ha-markdown
.content=${this._computeStepDescription(step)}
></ha-markdown>
`
: html``}`;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return html` ${this._computeStepDescription(step)
? html`
<ha-markdown
.content=${this._computeStepDescription(step)}
></ha-markdown>
`
: html``}`;
const description = this._computeStepDescription(step)
return description ? html`
<ha-markdown
.content=${description}
></ha-markdown>
: ""};

Comment on lines +351 to +352
this._state = "error";
this._errorMessage = "Login window was blocked, please allow popups.";
Copy link
Member

Choose a reason for hiding this comment

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

Give the user the option to open it manually, browsers often do allow opening a window with user interaction


const newStep = await response.json();

if (response.status === 403) {
Copy link
Member

Choose a reason for hiding this comment

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

Check response.ok

@christiaangoossens
Copy link
Author

Thanks for the review! I will refactor it a bit and add a button to trigger the new tab if it does not open.

One question for me remains open: what's your opinion on if window.open is the right call here? It's the legacy way to do OpenID Connect (with popups) so it works (at least on PC), but I don't see it working well on mobile.

@christiaangoossens christiaangoossens marked this pull request as draft December 1, 2022 13:59
@bramkragten
Copy link
Member

@christiaangoossens
Copy link
Author

Because of https://developer.mozilla.org/en-US/docs/Web/API/Window/open#avoid_resorting_to_window.open, I would like to avoid window.open, is registering a callback route an option here? Would that work in general with the flow steps?

I will look into it in the weekend.

@bramkragten
Copy link
Member

Callback requires backend support, but yeah I think that is the best way.

@github-actions
Copy link

github-actions bot commented Mar 5, 2023

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Mar 5, 2023
@christiaangoossens
Copy link
Author

Still interested in this, but it is stale, I would welcome other contributors. This is blocking OpenID Connect extension options.

@github-actions github-actions bot removed the stale label Mar 6, 2023
@github-actions github-actions bot closed this Mar 13, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Mar 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants