Android: get login working

This commit is contained in:
Pieter Vander Vennet 2024-12-31 19:55:08 +01:00
parent b165ec6005
commit 917fe6a0f9
2 changed files with 14 additions and 8 deletions

View file

@ -32,7 +32,7 @@
<!-- Include one or more domains that should be verified. -->
<data android:host="app.mapcomplete.org" />
<data android:path="/land.html" />
<data android:path="/passthrough.html" />
</intent-filter>
</activity>

View file

@ -21,6 +21,8 @@ public class MainActivity extends BridgeActivity {
private PluginCall locationRequest = null;
private PluginCall authRequest = null;
private JSObject loginToken = null;
@Override
public void onCreate(Bundle savedInstanceState) {
registerPlugin(Databridge.class);
@ -31,6 +33,9 @@ public class MainActivity extends BridgeActivity {
});
Databridge.addResponder("request:login", pluginCall -> {
this.authRequest = pluginCall;
if(this.loginToken != null){
pluginCall.resolve(this.loginToken);
}
});
super.onCreate(savedInstanceState);
}
@ -62,16 +67,17 @@ public class MainActivity extends BridgeActivity {
return;
}
if (Objects.equals(url.getPath(), "/land.html")) {
var code = url.getQueryParameter("code");
var state = url.getQueryParameter("state");
if (Objects.equals(url.getPath(), "/passthrough.html")) {
var token = url.getQueryParameter("oauth_token");
JSObject obj = new JSObject();
obj.put("code", code);
obj.put("state", state);
obj.put("oauth_token", token);
JSObject res = new JSObject();
res.put("value", obj);
Log.i("main", "Resolving auth call");
this.authRequest.resolve(res);
Log.i("main", "Resolving auth call, param is " + token);
this.loginToken = res;
if(this.authRequest != null){
this.authRequest.resolve(res);
}
return;
}