Skip to content

Convert SmartThings setup from PAT to OAuth credentials#36

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/update-authentication-method
Closed

Convert SmartThings setup from PAT to OAuth credentials#36
Copilot wants to merge 2 commits intomainfrom
copilot/update-authentication-method

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 31, 2026

The integration required a Personal Access Token (PAT) to dynamically create a SmartApp and generate OAuth credentials at setup time. This replaces that flow with direct OAuth credentials (App ID, Client ID, Client Secret) pre-registered in the SmartThings Developer Portal.

Config flow (config_flow.py)

  • async_step_pat + async_step_select_locationasync_step_oauth_credentials
  • User inputs App ID, Client ID, Client Secret; location selection removed — location_id is delivered via the INSTALL webhook callback and forwarded into async_step_authorize
  • async_step_install exchanges the received refresh_token for an access_token via generate_tokens() before creating the config entry
  • app_id stored in flow context so the webhook dispatcher can match callbacks to in-progress flows

Webhook / SmartApp registration (smartapp.py, pysmartapp/)

  • New setup_smartapp_for_oauth(hass, app_id) registers a SmartApp with public_key=None so INSTALL callbacks can be dispatched before an access token is available
  • _find_and_continue_flow gains a fallback: matches an authorize-step flow by context["app_id"] when unique_id is not yet set, and forwards location_id via _continue_flow
  • setup_smartapp now updates public_key on an already-registered SmartApp
  • Signature verification skipped when public_key is None; re-enabled in async_setup_entry once the full app info is fetched with the OAuth token

Other

  • format_install_url: location_id made optional — lets SmartThings prompt the user to pick a location on its authorization page
  • SmartApp.public_key made settable
  • async_setup_entry: applies webhook_public_key to a SmartApp registered without one during OAuth setup
  • strings.json, translations/en.json, translations/ko.json: new oauth_credentials step strings; PAT/location-selection strings removed

Replace the Personal Access Token (PAT) setup step with an OAuth
credentials step (App ID, Client ID, Client Secret) obtained from the
SmartThings Developer Portal.

Key changes:
- config_flow.py: new async_step_oauth_credentials replaces
  async_step_pat; location selection removed (delivered via INSTALL
  webhook); async_step_install generates OAuth tokens directly
- smartapp.py: add setup_smartapp_for_oauth(); update
  _find_and_continue_flow() to match OAuth flows by app_id; extend
  _continue_flow() with optional location_id parameter
- pysmartapp/smartapp.py: add public_key setter to SmartApp
- pysmartapp/request.py: skip signature verification when public_key
  is None (initial OAuth setup window)
- pysmartthings/installedapp.py: make location_id optional in
  format_install_url()
- __init__.py: update SmartApp public key after OAuth token acquired
- strings.json, translations/en.json, translations/ko.json: new
  oauth_credentials step UI strings

Agent-Logs-Url: https://github.com/oukene/smartthings_customize/sessions/6e4566b2-151d-4214-b459-53f3c4fe4cc6

Co-authored-by: oukene <19838374+oukene@users.noreply.github.com>
Copilot AI changed the title [WIP] Update authentication method to OAuth for SmartThings integration Convert SmartThings setup from PAT to OAuth credentials Mar 31, 2026
Copilot AI requested a review from oukene March 31, 2026 07:16
@oukene oukene closed this Mar 31, 2026
@oukene oukene reopened this Mar 31, 2026
@oukene oukene closed this Mar 31, 2026
@oukene oukene deleted the copilot/update-authentication-method branch March 31, 2026 08:16
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.

2 participants