diff --git a/locales/en/translation.json b/locales/en/translation.json index 8ee2ee80..1915740c 100644 --- a/locales/en/translation.json +++ b/locales/en/translation.json @@ -81,6 +81,7 @@ "finish": "Finish", "authorization_code": "Authorization Code", "authorization_help": "Please paste the authorization code from your browser", + "without_code_authorize": "Please approve Fedistar in your browser, and after you approve it please authorize", "authorize": "Authorize", "loading": "Loading" } diff --git a/package.json b/package.json index b101109a..836df3f6 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@tauri-apps/api": "^1.3.0", "dayjs": "^1.11.8", "emoji-mart": "^5.5.2", - "megalodon": "^8.0.0", + "megalodon": "^8.1.0", "next": "^13.4.5", "parse-link-header": "^2.0.0", "react": "^18.2.0", diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index bb3fde47..15f32f51 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -100,16 +100,7 @@ async fn add_application( ); let options = megalodon::megalodon::AppInputOptions { - redirect_uris: None, - scopes: Some( - [ - "read".to_string(), - "write".to_string(), - "follow".to_string(), - ] - .to_vec(), - ), - website: None, + ..Default::default() }; let app_data = client .register_app(String::from("Fedistar"), &options) @@ -142,11 +133,17 @@ async fn authorize_code( let client_id = app.client_id; let client_secret = app.client_secret; + let authorization_code = if let Some(session_token) = app.session_token { + session_token + } else { + code.to_string() + }; + let token_data = client .fetch_access_token( client_id.clone(), client_secret.clone(), - code.to_string(), + authorization_code, megalodon::default::NO_REDIRECT.to_string(), ) .await diff --git a/src/components/servers/New.tsx b/src/components/servers/New.tsx index c3095284..c361d071 100644 --- a/src/components/servers/New.tsx +++ b/src/components/servers/New.tsx @@ -17,7 +17,7 @@ const New: React.FC = props => { const { formatMessage } = useIntl() const [server, setServer] = useState() - const [app, setApp] = useState() + const [app, setApp] = useState() const [loading, setLoading] = useState(false) const [domain, setDomain] = useState('') const [code, setCode] = useState('') @@ -48,7 +48,7 @@ const New: React.FC = props => { async function addApplication() { setLoading(true) try { - const res = await invoke('add_application', { url: server.base_url }) + const res = await invoke('add_application', { url: server.base_url }) setApp(res) } catch (err) { console.error(err) @@ -141,15 +141,21 @@ const New: React.FC = props => { )} {app !== undefined && (
setCode(o.code)}> - - - - - - - - - + {app.session_token ? ( +
+ +
+ ) : ( + + + + + + + + + + )}