forked from MapComplete/MapComplete
Android: add passthrough pages
This commit is contained in:
parent
969ad74bd9
commit
a34abb702c
6 changed files with 104 additions and 0 deletions
10
app/.well-known/assetlinks.json
Normal file
10
app/.well-known/assetlinks.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
[{
|
||||
"relation": ["delegate_permission/common.handle_all_urls"],
|
||||
"target": {
|
||||
"namespace": "android_app",
|
||||
"package_name": "org.mapcomplete",
|
||||
"sha256_cert_fingerprints":
|
||||
["16:76:16:29:FE:F7:61:C1:E8:52:2E:63:89:E9:A2:B2:76:87:16:79:E4:D4:92:17:35:B6:3A:17:90:6D:35:6C"]
|
||||
}
|
||||
}]
|
||||
|
28
app/README.md
Normal file
28
app/README.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
# app-directory
|
||||
|
||||
This directory contains the files for "https://app.mapcomplete.org". This does _not_ contain the Android files, but it contains some helper HTML.
|
||||
|
||||
The main function is to help authentication.
|
||||
|
||||
The authentication flow in a nutshell:
|
||||
|
||||
1. The user want to authenticate
|
||||
2. The app opens a browser window, showing the OSM.org login page
|
||||
3. The browser redirects to "app.mapcomplete.org/land.html"; which obtains an authentication token
|
||||
4. Once the token is obtained, the browser redirects to "app.mapcomplete.org/passthrough.html?auth_token=<...>".
|
||||
5. This URL is an "authenticated URL" and will thus be opened in the app, where
|
||||
6. The native shell receives the intent with the authentication token
|
||||
7. The native shell passes this to the web context
|
||||
8. The webcontext passes the token to the OSM-connection
|
||||
9. ???
|
||||
10. Profit!
|
||||
|
||||
## The 'assetlinks-file'
|
||||
|
||||
The hidden folder ".well-known" should be put on the website as well; `https://app.mapcomplete.org/.well-known/assetlinks.json` must return the relevant JSON
|
||||
|
||||
## A note about building and deploying
|
||||
|
||||
These files should be relatively static and not change a lot. The deploy script is included in this directory (but not in CI)
|
||||
|
||||
These are deployed in the hetzner server in the `/root/app/*`-directory; see [the hetzner caddyfile](../Docs/ServerConfig/hetzner/Caddyfile) for more info
|
28
app/app.vite.config.js
Normal file
28
app/app.vite.config.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { defineConfig } from "vite"
|
||||
import { svelte } from "@sveltejs/vite-plugin-svelte"
|
||||
import fs from "fs"
|
||||
import basicSsl from "@vitejs/plugin-basic-ssl"
|
||||
|
||||
const input = { "land": "./app/land.html", passthrough: "./app/passthrough.html" }
|
||||
|
||||
|
||||
console.log("Args:", process.argv)
|
||||
const plugins = [svelte()]
|
||||
if (process.argv.indexOf("--https") >= 0) {
|
||||
console.log("Adding basicSSL")
|
||||
plugins.push(basicSsl())
|
||||
}
|
||||
const ASSET_URL = process.env.ASSET_URL || ""
|
||||
export default defineConfig({
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input,
|
||||
},
|
||||
outDir: "./app/dist/",
|
||||
},
|
||||
base: `./app/`,
|
||||
plugins,
|
||||
server: {
|
||||
port: 1234,
|
||||
},
|
||||
})
|
19
app/build_and_deploy.sh
Executable file
19
app/build_and_deploy.sh
Executable file
|
@ -0,0 +1,19 @@
|
|||
#! /bin/bash
|
||||
|
||||
nvm use
|
||||
export NODE_OPTIONS="--max-old-space-size=8192"
|
||||
|
||||
npm run build:vite:app-landing
|
||||
|
||||
mkdir to_upload
|
||||
mv dist/app/* to_upload/
|
||||
cp -r .well-known/ to_upload/
|
||||
mkdir -p to_upload/assets
|
||||
cp dist/assets/*.js to_upload/assets/
|
||||
rm -rf dist
|
||||
|
||||
ssh hetzner "rm -rf /root/app/"
|
||||
scp -rp to_upload/ hetzner:/root/app/
|
||||
scp -rp to_upload/.well-known/ hetzner:/root/app/
|
||||
|
||||
rm -rf to_upload
|
8
app/land.html
Normal file
8
app/land.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>MapComplete Auth</title></head>
|
||||
<body>
|
||||
Authorizing and redirecting, hang on...
|
||||
<script type="module" src="./land.ts"></script>
|
||||
</body>
|
||||
</html>
|
11
app/land.ts
Normal file
11
app/land.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { OsmConnection } from "../src/Logic/Osm/OsmConnection"
|
||||
import Constants from "../src/Models/Constants"
|
||||
|
||||
console.log("Authorizing...")
|
||||
const key = Constants.osmAuthConfig.url + "oauth2_state"
|
||||
const st =window.localStorage.getItem(key )
|
||||
console.log("Prev state is",key, st)
|
||||
new OsmConnection().finishLogin((_, token: string) => {
|
||||
console.log("Login finished, redirecting to passthrough")
|
||||
window.location.href = "https://app.mapcomplete.org/passthrough.html?oauth_token="+token
|
||||
})
|
Loading…
Add table
Reference in a new issue