fix: expose config for farmOS OAuth2 client_id and scope

refs: #3
This commit is contained in:
Lance Edgar 2026-02-25 14:36:28 -06:00
parent ec6ac443fb
commit df517cfbfa
4 changed files with 43 additions and 3 deletions

View file

@ -94,3 +94,9 @@ class FarmOSHandler(GenericHandler):
return f"{base}/{path}" return f"{base}/{path}"
return base return base
def get_oauth2_client_id(self):
return self.config.get("farmos.oauth2.client_id", default="farm")
def get_oauth2_scope(self):
return self.config.get("farmos.oauth2.scope", default="farm_manager")

View file

@ -14,6 +14,28 @@
</b-input> </b-input>
</b-field> </b-field>
<b-field grouped>
<b-field label="OAuth2 Client ID">
<b-input name="farmos.oauth2.client_id"
v-model="simpleSettings['farmos.oauth2.client_id']"
@input="settingsNeedSaved = true">
</b-input>
</b-field>
<b-field label="OAuth2 Scope">
<b-input name="farmos.oauth2.scope"
v-model="simpleSettings['farmos.oauth2.scope']"
@input="settingsNeedSaved = true">
</b-input>
</b-field>
</b-field>
<b-field label="OAuth2 Redirect URI">
<wutta-copyable-text text="${url('farmos_oauth_callback')}" />
</b-field>
<b-field label="farmOS Integration Mode"> <b-field label="farmOS Integration Mode">
<b-select name="${app.appname}.farmos_integration_mode" <b-select name="${app.appname}.farmos_integration_mode"
v-model="simpleSettings['${app.appname}.farmos_integration_mode']" v-model="simpleSettings['${app.appname}.farmos_integration_mode']"

View file

@ -55,9 +55,10 @@ class AuthView(base.AuthView):
return None return None
def get_farmos_oauth2_session(self): def get_farmos_oauth2_session(self):
farmos = self.app.get_farmos_handler()
return OAuth2Session( return OAuth2Session(
client_id="farm", client_id=farmos.get_oauth2_client_id(),
scope="farm_manager", scope=farmos.get_oauth2_scope(),
redirect_uri=self.request.route_url("farmos_oauth_callback"), redirect_uri=self.request.route_url("farmos_oauth_callback"),
) )

View file

@ -57,10 +57,21 @@ class AppInfoView(base.AppInfoView):
return info return info
def configure_get_simple_settings(self): # pylint: disable=empty-docstring def configure_get_simple_settings(self): # pylint: disable=empty-docstring
farmos = self.app.get_farmos_handler()
simple_settings = super().configure_get_simple_settings() simple_settings = super().configure_get_simple_settings()
simple_settings.extend( simple_settings.extend(
[ [
{"name": "farmos.url.base"}, {
"name": "farmos.url.base",
},
{
"name": "farmos.oauth2.client_id",
"default": farmos.get_oauth2_client_id(),
},
{
"name": "farmos.oauth2.scope",
"default": farmos.get_oauth2_scope(),
},
{ {
"name": f"{self.app.appname}.farmos_integration_mode", "name": f"{self.app.appname}.farmos_integration_mode",
"default": self.app.get_farmos_integration_mode(), "default": self.app.get_farmos_integration_mode(),