fix(frontend): fix early access authentication

This commit is contained in:
liushuyu 2021-10-15 18:34:13 -06:00
parent e990138200
commit 3196736d36
7 changed files with 17 additions and 24 deletions

12
Cargo.lock generated
View file

@ -1423,7 +1423,7 @@ dependencies = [
"walkdir", "walkdir",
"webbrowser", "webbrowser",
"which", "which",
"widestring 0.5.0", "widestring",
"winapi 0.3.9", "winapi 0.3.9",
"winres", "winres",
"wry", "wry",
@ -3364,7 +3364,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecad156490d6b620308ed411cfee90d280b3cbd13e189ea0d3fada8acc89158a" checksum = "ecad156490d6b620308ed411cfee90d280b3cbd13e189ea0d3fada8acc89158a"
dependencies = [ dependencies = [
"web-sys", "web-sys",
"widestring 0.4.3", "widestring",
"winapi 0.3.9", "winapi 0.3.9",
] ]
@ -3423,7 +3423,7 @@ dependencies = [
"com", "com",
"once_cell", "once_cell",
"webview2-sys", "webview2-sys",
"widestring 0.4.3", "widestring",
"winapi 0.3.9", "winapi 0.3.9",
] ]
@ -3454,12 +3454,6 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c"
[[package]]
name = "widestring"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15be6395051be4e41efeee975b7561b8c602ba30204bfa35fefa0f85582075b6"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.2.8" version = "0.2.8"

View file

@ -57,7 +57,7 @@ which = "4.0"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["psapi", "winbase", "winioctl", "winnt"] } winapi = { version = "0.3", features = ["psapi", "winbase", "winioctl", "winnt"] }
widestring = "0.5" widestring = "0.4"
[target.'cfg(not(windows))'.dependencies] [target.'cfg(not(windows))'.dependencies]
sysinfo = "0.20" sysinfo = "0.20"

View file

@ -128,14 +128,10 @@ pub fn validate_token(
) -> Result<JWTClaims, String> { ) -> Result<JWTClaims, String> {
// Get the public key for this authentication url // Get the public key for this authentication url
let pub_key = if pub_key_base64.is_empty() { let pub_key = if pub_key_base64.is_empty() {
DecodingKey::from_secret(&[]) vec![]
} else { } else {
DecodingKey::from_base64_secret(&pub_key_base64).map_err(|e| { base64::decode(&pub_key_base64)
format!( .map_err(|e| format!("Configured public key was not empty and did not decode as base64 {:?}", e))?
"Configured public key was not empty and did not decode as base64 {:?}",
e
)
})?
}; };
// Configure validation for audience and issuer if the configuration provides it // Configure validation for audience and issuer if the configuration provides it
@ -153,7 +149,7 @@ pub fn validate_token(
validation.validate_exp = false; validation.validate_exp = false;
validation.validate_nbf = false; validation.validate_nbf = false;
// Verify the JWT token // Verify the JWT token
decode::<JWTClaims>(&body, &pub_key, &validation) decode::<JWTClaims>(&body, &DecodingKey::from_rsa_der(&pub_key), &validation)
.map(|tok| tok.claims) .map(|tok| tok.claims)
.map_err(|err| { .map_err(|err| {
format!( format!(

View file

@ -20,7 +20,6 @@ mod natives {
use std::env; use std::env;
use std::os::windows::ffi::OsStrExt; use std::os::windows::ffi::OsStrExt;
use std::path::Path; use std::path::Path;
use std::process::Command;
use winapi::shared::minwindef::{DWORD, FALSE, MAX_PATH}; use winapi::shared::minwindef::{DWORD, FALSE, MAX_PATH};

View file

@ -1,3 +1 @@
> 1% > 1%
last 2 versions
not ie <= 11

View file

@ -10,6 +10,9 @@ import messages from './locales/messages.json'
import 'buefy/dist/buefy.css' import 'buefy/dist/buefy.css'
import '@mdi/font/css/materialdesignicons.min.css' import '@mdi/font/css/materialdesignicons.min.css'
// HACK: disables context menu
document.addEventListener('contextmenu', event => event.preventDefault())
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.use(Buefy) Vue.use(Buefy)
Vue.use(VueI18n) Vue.use(VueI18n)

View file

@ -19,9 +19,9 @@
<section> <section>
<p>{{ $t('auth.token') }}</p> <p>{{ $t('auth.token') }}</p>
<b-field> <b-field>
<b-input type="text" v-model="combined_token" placeholder="Token" id="token" style='width: 50em;'></b-input> <b-input type="text" v-model="combined_token" placeholder="Token" id="token" style='width: 80%;'></b-input>
<p class="control"> <p class="control">
<button class="button is-info" v-on:click="paste">{{ $t('auth.paste') }}</button> <b-button type="is-info" v-on:click="paste">{{ $t('auth.paste') }}</b-button>
</p> </p>
</b-field> </b-field>
</section> </section>
@ -130,7 +130,10 @@ export default {
}, },
paste: function () { paste: function () {
document.getElementById('token').focus() document.getElementById('token').focus()
document.execCommand('paste') const that = this
navigator.clipboard.readText().then(function (v) {
that.combined_token = v
}).catch(function () {})
}, },
launch_browser: function (url) { launch_browser: function (url) {
const that = this const that = this