Skip to content

Commit

Permalink
refs #1018 Fix authorization flow for Firefish
Browse files Browse the repository at this point in the history
  • Loading branch information
h3poteto committed Sep 27, 2023
1 parent f2416c3 commit 6066d4a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
1 change: 1 addition & 0 deletions locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 8 additions & 11 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
28 changes: 17 additions & 11 deletions src/components/servers/New.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const New: React.FC<Props> = props => {
const { formatMessage } = useIntl()

const [server, setServer] = useState<Server>()
const [app, setApp] = useState<OAuth.AppDataFromServer>()
const [app, setApp] = useState<OAuth.AppData>()
const [loading, setLoading] = useState<boolean>(false)
const [domain, setDomain] = useState('')
const [code, setCode] = useState('')
Expand Down Expand Up @@ -48,7 +48,7 @@ const New: React.FC<Props> = props => {
async function addApplication() {
setLoading(true)
try {
const res = await invoke<OAuth.AppDataFromServer>('add_application', { url: server.base_url })
const res = await invoke<OAuth.AppData>('add_application', { url: server.base_url })
setApp(res)
} catch (err) {
console.error(err)
Expand Down Expand Up @@ -141,15 +141,21 @@ const New: React.FC<Props> = props => {
)}
{app !== undefined && (
<Form fluid onChange={o => setCode(o.code)}>
<Form.Group>
<Form.ControlLabel>
<FormattedMessage id="servers.new.authorization_code" />
</Form.ControlLabel>
<Form.Control name="code" />
<Form.HelpText>
<FormattedMessage id="servers.new.authorization_help" />
</Form.HelpText>
</Form.Group>
{app.session_token ? (
<div style={{ margin: '1em 0' }}>
<FormattedMessage id="servers.new.without_code_authorize" />
</div>
) : (
<Form.Group>
<Form.ControlLabel>
<FormattedMessage id="servers.new.authorization_code" />
</Form.ControlLabel>
<Form.Control name="code" />
<Form.HelpText>
<FormattedMessage id="servers.new.authorization_help" />
</Form.HelpText>
</Form.Group>
)}
<Form.Group>
<ButtonToolbar>
<Button appearance="primary" onClick={() => authorizeCode()}>
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3327,10 +3327,10 @@ makeerror@1.0.12:
dependencies:
tmpl "1.0.5"

megalodon@^8.0.0:
version "8.0.1"
resolved "https://registry.yarnpkg.com/megalodon/-/megalodon-8.0.1.tgz#76dc2762bcf0411430cf8dea3645c02fd5bf4457"
integrity sha512-JkdITfLMepG6COxs3J2YK2s/PYEMPerk0bRoTJsXezISB8uuM7P2KjDP0bOakd7NikjG5EjOhbxE2hl+ACcccA==
megalodon@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/megalodon/-/megalodon-8.1.0.tgz#76dedd58e456cd73abccf61b533c80fd560e88a0"
integrity sha512-7tl6iHOBX8JbAv4ka0o85r9/Ulvf9lQv0KUkB/7W0hiMWqluH3sbTCZbkBU+2Hq1kIwWCAuyZB3gxcbn8FoZIg==
dependencies:
"@types/oauth" "^0.9.2"
"@types/ws" "^8.5.5"
Expand Down

0 comments on commit 6066d4a

Please sign in to comment.