weeeeeeeee
This commit is contained in:
@@ -19,16 +19,25 @@ async function ready() {
|
||||
|
||||
async function auth() {
|
||||
setMessage('Please wait');
|
||||
|
||||
const instance = document.getElementById('instance').value;
|
||||
const domain = instance.match(/(?:https?:\/\/)?(.*)/)[1];
|
||||
const matches = instance.match(/((?:http|https):\/\/)?(.*)/);
|
||||
|
||||
const protocol = matches[1];
|
||||
if (protocol) {
|
||||
localStorage.setItem('protocol', protocol);
|
||||
}
|
||||
|
||||
const domain = matches[2];
|
||||
if (!domain) {
|
||||
setMessage('Invalid instance', false);
|
||||
return;
|
||||
}
|
||||
|
||||
localStorage.setItem('domain', domain);
|
||||
|
||||
// We need to run this every time in cases like Iceshrimp, where the client id/secret aren't reusable (yet) because they contain use-once session information
|
||||
// We need to run this every time in cases like Iceshrimp,
|
||||
// where the client id/secret aren't reusable (yet) because
|
||||
// they contain use-once session information.
|
||||
await registerApp(domain);
|
||||
|
||||
authorize(domain);
|
||||
@@ -37,7 +46,8 @@ async function auth() {
|
||||
async function registerApp(domain) {
|
||||
setMessage('Registering app');
|
||||
|
||||
const appsUrl = `https://${domain}/api/v1/apps`;
|
||||
const protocol = localStorage.getItem(`protocol`) ?? `https://`;
|
||||
const appsUrl = `${protocol}${domain}/api/v1/apps`;
|
||||
const formData = new FormData();
|
||||
formData.append('client_name', 'Masto-FE standalone');
|
||||
formData.append('redirect_uris', document.location.origin + document.location.pathname);
|
||||
@@ -61,13 +71,15 @@ async function registerApp(domain) {
|
||||
function authorize(domain) {
|
||||
setMessage('Authorizing');
|
||||
const clientId = localStorage.getItem(`client_id`);
|
||||
document.location.href = `https://${domain}/oauth/authorize?response_type=code&client_id=${clientId}&redirect_uri=${document.location.origin + document.location.pathname}&scope=read+write+follow+push`;
|
||||
const protocol = localStorage.getItem(`protocol`) ?? `https://`;
|
||||
document.location.href = `${protocol}${domain}/oauth/authorize?response_type=code&client_id=${clientId}&redirect_uri=${document.location.origin + document.location.pathname}&scope=read+write+follow+push`;
|
||||
}
|
||||
|
||||
async function getToken(code, domain) {
|
||||
setMessage('Getting token');
|
||||
|
||||
const tokenUrl = `https://${domain}/oauth/token`;
|
||||
const protocol = localStorage.getItem(`protocol`) ?? `https://`;
|
||||
const tokenUrl = `${protocol}${domain}/oauth/token`;
|
||||
const clientId = localStorage.getItem(`client_id`);
|
||||
const clientSecret = localStorage.getItem(`client_secret`);
|
||||
|
||||
@@ -98,4 +110,4 @@ async function getToken(code, domain) {
|
||||
function setMessage(message, disabled = true) {
|
||||
document.getElementById('message').textContent = message;
|
||||
document.getElementById('btn').disabled = disabled;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 22 KiB |
Reference in New Issue
Block a user