add Pleroma refreshable token
This commit is contained in:
parent
eaec63adb8
commit
cc5ba8af0f
|
@ -89,3 +89,6 @@ i.left {
|
||||||
#domain-list .title {
|
#domain-list .title {
|
||||||
font-size: 1.3rem;
|
font-size: 1.3rem;
|
||||||
}
|
}
|
||||||
|
.text-line-icon {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
|
@ -298,18 +298,24 @@ function getdataAdv(domain, at) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
//ユーザーデータ更新
|
//ユーザーデータ更新
|
||||||
function refresh(target, loadskip) {
|
async function refresh(target, loadskip) {
|
||||||
var multi = localStorage.getItem('multi')
|
var multi = localStorage.getItem('multi')
|
||||||
var obj = JSON.parse(multi)
|
var obj = JSON.parse(multi)
|
||||||
if (obj[target].mode == 'misskey') {
|
if (obj[target].mode == 'misskey') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
let at = obj[target].at
|
||||||
|
if (obj[target].rt) {
|
||||||
|
console.log('refresh access token')
|
||||||
|
at = await refreshPleromaAt(obj[target])
|
||||||
|
localStorage.setItem(`acct_${target}_at`, at)
|
||||||
|
}
|
||||||
var start = 'https://' + obj[target].domain + '/api/v1/accounts/verify_credentials'
|
var start = 'https://' + obj[target].domain + '/api/v1/accounts/verify_credentials'
|
||||||
fetch(start, {
|
fetch(start, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/json',
|
||||||
Authorization: 'Bearer ' + obj[target].at
|
Authorization: 'Bearer ' + at
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
@ -369,6 +375,29 @@ function refresh(target, loadskip) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
async function refreshPleromaAt(obj) {
|
||||||
|
const start = 'https://' + obj.domain + '/oauth/token'
|
||||||
|
const rt = obj.rt.split(' ')
|
||||||
|
let promise = await fetch(start, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
grant_type : 'refresh_token',
|
||||||
|
refresh_token: rt[0],
|
||||||
|
client_id: rt[1],
|
||||||
|
client_secret: rt[2]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const json = await promise.json()
|
||||||
|
if (json.access_token) {
|
||||||
|
return json.access_token
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
//MarkdownやBBCodeの対応、文字数制限をチェック
|
//MarkdownやBBCodeの対応、文字数制限をチェック
|
||||||
//絶対ストリーミングを閉じさせないマン
|
//絶対ストリーミングを閉じさせないマン
|
||||||
function ckdb(acct_id) {
|
function ckdb(acct_id) {
|
||||||
|
|
|
@ -55,6 +55,9 @@ function load() {
|
||||||
<div class="card-content ">
|
<div class="card-content ">
|
||||||
<span class="lts">${list}.</span><img src="${acct.prof}" width="40" height="40" />
|
<span class="lts">${list}.</span><img src="${acct.prof}" width="40" height="40" />
|
||||||
<span class="card-title">${name}</span>${escapeHTML(acct.user)}@${acct.domain}
|
<span class="card-title">${name}</span>${escapeHTML(acct.user)}@${acct.domain}
|
||||||
|
<a onclick="login('${acct.domain}')" class="pointer white-text waves-effect" title="${lang.lang_manager_refreshAt}">
|
||||||
|
<i class="material-icons text-line-icon">login</i>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-action">
|
<div class="card-action">
|
||||||
<button class="btn-flat waves-effect disTar pointer white-text" onclick="refresh('${key}')">
|
<button class="btn-flat waves-effect disTar pointer white-text" onclick="refresh('${key}')">
|
||||||
|
@ -227,7 +230,9 @@ function multiDel(target) {
|
||||||
var olddom = localStorage.getItem('domain_' + key)
|
var olddom = localStorage.getItem('domain_' + key)
|
||||||
localStorage.setItem('domain_' + nk, olddom)
|
localStorage.setItem('domain_' + nk, olddom)
|
||||||
var oldat = localStorage.getItem('acct_' + key + '_at')
|
var oldat = localStorage.getItem('acct_' + key + '_at')
|
||||||
|
var oldrt = localStorage.getItem('acct_' + key + '_rt')
|
||||||
localStorage.setItem('acct_' + nk + '_at', oldat)
|
localStorage.setItem('acct_' + nk + '_at', oldat)
|
||||||
|
localStorage.setItem('acct_' + nk + '_rt', oldrt)
|
||||||
localStorage.setItem('name_' + nk, localStorage.getItem('name_' + key))
|
localStorage.setItem('name_' + nk, localStorage.getItem('name_' + key))
|
||||||
localStorage.setItem('user_' + target, localStorage.getItem('user_' + key))
|
localStorage.setItem('user_' + target, localStorage.getItem('user_' + key))
|
||||||
localStorage.setItem('user-id_' + target, localStorage.getItem('user-id_' + key))
|
localStorage.setItem('user-id_' + target, localStorage.getItem('user-id_' + key))
|
||||||
|
@ -631,7 +636,6 @@ function instance() {
|
||||||
}
|
}
|
||||||
login(url)
|
login(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
//コード入れてAccessTokenゲット
|
//コード入れてAccessTokenゲット
|
||||||
function code(code) {
|
function code(code) {
|
||||||
localStorage.removeItem('redirect')
|
localStorage.removeItem('redirect')
|
||||||
|
@ -725,14 +729,16 @@ function code(code) {
|
||||||
if (json['access_token']) {
|
if (json['access_token']) {
|
||||||
$('#auth').hide()
|
$('#auth').hide()
|
||||||
$('#add').show()
|
$('#add').show()
|
||||||
getdata(url, json['access_token'])
|
getdata(url, json)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//ユーザーデータ取得
|
//ユーザーデータ取得
|
||||||
function getdata(domain, at) {
|
function getdata(domain, json) {
|
||||||
|
var at = json['access_token']
|
||||||
|
var rt = `${json['refresh_token']} ${localStorage.getItem('client_id')} ${localStorage.getItem('client_secret')}`
|
||||||
var start = 'https://' + domain + '/api/v1/accounts/verify_credentials'
|
var start = 'https://' + domain + '/api/v1/accounts/verify_credentials'
|
||||||
fetch(start, {
|
fetch(start, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
@ -772,6 +778,7 @@ function getdata(domain, at) {
|
||||||
}
|
}
|
||||||
var add = {
|
var add = {
|
||||||
at: at,
|
at: at,
|
||||||
|
rt: rt ? rt : null,
|
||||||
name: json['display_name'],
|
name: json['display_name'],
|
||||||
domain: domain,
|
domain: domain,
|
||||||
user: json['acct'],
|
user: json['acct'],
|
||||||
|
@ -782,8 +789,24 @@ function getdata(domain, at) {
|
||||||
}
|
}
|
||||||
var multi = localStorage.getItem('multi')
|
var multi = localStorage.getItem('multi')
|
||||||
var obj = JSON.parse(multi)
|
var obj = JSON.parse(multi)
|
||||||
|
let addTarget = -1
|
||||||
|
let ct = 0
|
||||||
|
for (let acct of obj) {
|
||||||
|
if (acct.domain === domain && acct.user === json['acct']) {
|
||||||
|
console.log('detected dupl addct')
|
||||||
|
addTarget = ct
|
||||||
|
break
|
||||||
|
}
|
||||||
|
ct++
|
||||||
|
}
|
||||||
|
if (addTarget == -1) {
|
||||||
var target = obj.length
|
var target = obj.length
|
||||||
obj.push(add)
|
obj.push(add)
|
||||||
|
} else {
|
||||||
|
console.log('dupl acct_' + addTarget)
|
||||||
|
obj[addTarget] = add
|
||||||
|
var target = addTarget
|
||||||
|
}
|
||||||
localStorage.setItem('name_' + target, json['display_name'])
|
localStorage.setItem('name_' + target, json['display_name'])
|
||||||
localStorage.setItem('user_' + target, json['acct'])
|
localStorage.setItem('user_' + target, json['acct'])
|
||||||
localStorage.setItem('user-id_' + target, json['id'])
|
localStorage.setItem('user-id_' + target, json['id'])
|
||||||
|
@ -807,6 +830,7 @@ function atSetup(type) {
|
||||||
var i = $('#misskey-key').val()
|
var i = $('#misskey-key').val()
|
||||||
var add = {
|
var add = {
|
||||||
at: i,
|
at: i,
|
||||||
|
rt: null,
|
||||||
name: 'Pseudo Account',
|
name: 'Pseudo Account',
|
||||||
domain: url,
|
domain: url,
|
||||||
user: 'user+pseudo',
|
user: 'user+pseudo',
|
||||||
|
@ -820,6 +844,7 @@ function atSetup(type) {
|
||||||
var i = $('#code').val()
|
var i = $('#code').val()
|
||||||
var add = {
|
var add = {
|
||||||
at: i,
|
at: i,
|
||||||
|
rt: null,
|
||||||
name: 'Pseudo Account',
|
name: 'Pseudo Account',
|
||||||
domain: url,
|
domain: url,
|
||||||
user: 'user+pseudo',
|
user: 'user+pseudo',
|
||||||
|
@ -893,6 +918,7 @@ function refresh(target) {
|
||||||
}
|
}
|
||||||
var ref = {
|
var ref = {
|
||||||
at: obj[target].at,
|
at: obj[target].at,
|
||||||
|
rt: obj[target].rt ? obj[target].rt : null,
|
||||||
name: json['display_name'],
|
name: json['display_name'],
|
||||||
domain: obj[target].domain,
|
domain: obj[target].domain,
|
||||||
user: json['acct'],
|
user: json['acct'],
|
||||||
|
@ -944,6 +970,7 @@ function misskeyRefresh(obj, target, url) {
|
||||||
var priv = 'public'
|
var priv = 'public'
|
||||||
var add = {
|
var add = {
|
||||||
at: json.accessToken,
|
at: json.accessToken,
|
||||||
|
rt: null,
|
||||||
name: json['user']['name'],
|
name: json['user']['name'],
|
||||||
domain: url,
|
domain: url,
|
||||||
user: json['user']['username'],
|
user: json['user']['username'],
|
||||||
|
|
|
@ -51,6 +51,7 @@ function parseColumn(target, dontclose) {
|
||||||
localStorage.setItem('prof_' + key, acct.prof)
|
localStorage.setItem('prof_' + key, acct.prof)
|
||||||
localStorage.setItem('domain_' + key, acct.domain)
|
localStorage.setItem('domain_' + key, acct.domain)
|
||||||
localStorage.setItem('acct_' + key + '_at', acct.at)
|
localStorage.setItem('acct_' + key + '_at', acct.at)
|
||||||
|
localStorage.setItem('acct_' + key + '_rt', acct.rt ? acct.rt : null)
|
||||||
if(!target) mastodonBaseStreaming(key)
|
if(!target) mastodonBaseStreaming(key)
|
||||||
ckdb(key)
|
ckdb(key)
|
||||||
//フィルターデータ読もう
|
//フィルターデータ読もう
|
||||||
|
|
|
@ -405,6 +405,7 @@ function importSettingsCore(obj) {
|
||||||
localStorage.setItem('prof_' + key, acct.prof)
|
localStorage.setItem('prof_' + key, acct.prof)
|
||||||
localStorage.setItem('domain_' + key, acct.domain)
|
localStorage.setItem('domain_' + key, acct.domain)
|
||||||
localStorage.setItem('acct_' + key + '_at', acct.at)
|
localStorage.setItem('acct_' + key + '_at', acct.at)
|
||||||
|
localStorage.setItem('acct_' + key + '_rt', acct.rt ? acct.rt : null)
|
||||||
}
|
}
|
||||||
localStorage.setItem('column', JSON.stringify(obj.columns))
|
localStorage.setItem('column', JSON.stringify(obj.columns))
|
||||||
if (obj.config) {
|
if (obj.config) {
|
||||||
|
|
|
@ -1,22 +1,16 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="@@lang@@">
|
<html lang="@@lang@@">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Account Manager - TheDesk</title>
|
<title>Account Manager - TheDesk</title>
|
||||||
<meta content="width=device-width,initial-scale=1.0" name="viewport" />
|
<meta content="width=device-width,initial-scale=1.0" name="viewport" />
|
||||||
<link href="../../css/themes.css" type="text/css" rel="stylesheet">
|
<link href="../../css/themes.css" type="text/css" rel="stylesheet">
|
||||||
<link
|
<link href="../../@@node_base@@/materialize-css/dist/css/materialize.css" type="text/css" rel="stylesheet" />
|
||||||
href="../../@@node_base@@/materialize-css/dist/css/materialize.css"
|
|
||||||
type="text/css"
|
|
||||||
rel="stylesheet"
|
|
||||||
/>
|
|
||||||
<link href="../../css/master.css" type="text/css" rel="stylesheet" />
|
<link href="../../css/master.css" type="text/css" rel="stylesheet" />
|
||||||
<link href="../../css/tl.css" rel="stylesheet" type="text/css" />
|
<link href="../../css/tl.css" rel="stylesheet" type="text/css" />
|
||||||
<link href="../../css/userdata.css" rel="stylesheet" type="text/css" />
|
<link href="../../css/userdata.css" rel="stylesheet" type="text/css" />
|
||||||
<link
|
<link href="../../@@node_base@@/@fortawesome/fontawesome-free/css/all.min.css" type="text/css" rel="stylesheet" />
|
||||||
href="../../@@node_base@@/@fortawesome/fontawesome-free/css/all.min.css"
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||||
type="text/css"
|
|
||||||
rel="stylesheet"
|
|
||||||
/>
|
|
||||||
<link href="../../css/acct.css" rel="stylesheet" type="text/css" />
|
<link href="../../css/acct.css" rel="stylesheet" type="text/css" />
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
@@comment-start@@
|
@@comment-start@@
|
||||||
|
@ -32,23 +26,15 @@
|
||||||
<body id="mainView" class="@@pwaClass@@">
|
<body id="mainView" class="@@pwaClass@@">
|
||||||
<script type="text/javascript" src="../../@@node_base@@/jquery/dist/jquery.js"></script>
|
<script type="text/javascript" src="../../@@node_base@@/jquery/dist/jquery.js"></script>
|
||||||
<script type="text/javascript" src="../../js/platform/first.js"></script>
|
<script type="text/javascript" src="../../js/platform/first.js"></script>
|
||||||
<script
|
<script type="text/javascript" src="../../@@node_base@@/materialize-css/dist/js/materialize.js"></script>
|
||||||
type="text/javascript"
|
|
||||||
src="../../@@node_base@@/materialize-css/dist/js/materialize.js"
|
|
||||||
></script>
|
|
||||||
<script type="text/javascript" src="main.js"></script>
|
<script type="text/javascript" src="main.js"></script>
|
||||||
<script
|
<script type="text/javascript" src="../../@@node_base@@/sweetalert2/dist/sweetalert2.all.min.js"></script>
|
||||||
type="text/javascript"
|
|
||||||
src="../../@@node_base@@/sweetalert2/dist/sweetalert2.all.min.js"
|
|
||||||
></script>
|
|
||||||
<script>
|
<script>
|
||||||
var misskeytoken = false
|
var misskeytoken = false
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="../../js/common/time.js"></script>
|
<script type="text/javascript" src="../../js/common/time.js"></script>
|
||||||
<div class="hide-first">
|
<div class="hide-first">
|
||||||
<a href="index.html" class="btn waves-effect orange nex" style="width:100%; max-width:200px;"
|
<a href="index.html" class="btn waves-effect orange nex" style="width:100%; max-width:200px;">@@back@@</a><br />
|
||||||
>@@back@@</a
|
|
||||||
><br />
|
|
||||||
<h5>@@list@@</h5>
|
<h5>@@list@@</h5>
|
||||||
<div id="acct-list"></div>
|
<div id="acct-list"></div>
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
|
@ -76,8 +62,7 @@
|
||||||
</div>
|
</div>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" class="filled-in" id="misskey" />
|
<input type="checkbox" class="filled-in" id="misskey" />
|
||||||
<span>@@thisismisskey@@</span> </label
|
<span>@@thisismisskey@@</span> </label><br />
|
||||||
><br />
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col s4 scr" aria-hidden="true">
|
<div class="col s4 scr" aria-hidden="true">
|
||||||
<span style="font-family:Open Sans;">Supports</span>
|
<span style="font-family:Open Sans;">Supports</span>
|
||||||
|
@ -93,11 +78,9 @@
|
||||||
<a onclick="atSetup()" class="pointer">@@accessTokenSetup@@</a>
|
<a onclick="atSetup()" class="pointer">@@accessTokenSetup@@</a>
|
||||||
<div id="compt" style="display:none" class="scr">
|
<div id="compt" style="display:none" class="scr">
|
||||||
<h5>ログイン前に必ずご確認ください</h5>
|
<h5>ログイン前に必ずご確認ください</h5>
|
||||||
<span id="compt-instance"></span>はバージョンが<span id="compt-ver"></span
|
<span id="compt-instance"></span>はバージョンが<span id="compt-ver"></span>のため以下の機能がご利用いただけません。
|
||||||
>のため以下の機能がご利用いただけません。
|
<span id="compt-warn"
|
||||||
<span id="compt-warn" style="display:none"
|
style="display:none">また、このインスタンスはMastodonではなくそのAPI上の互換実装であり、TheDeskでは利用を想定していないため非保証となります。</span>
|
||||||
>また、このインスタンスはMastodonではなくそのAPI上の互換実装であり、TheDeskでは利用を想定していないため非保証となります。</span
|
|
||||||
>
|
|
||||||
<ul id="compt-list"></ul>
|
<ul id="compt-list"></ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -116,12 +99,7 @@
|
||||||
<div class="input-field" style="width:300px">
|
<div class="input-field" style="width:300px">
|
||||||
<span data-trans="your_acct">@@selacct@@</span>
|
<span data-trans="your_acct">@@selacct@@</span>
|
||||||
<br />
|
<br />
|
||||||
<select
|
<select id="main-acct-sel" class="acct-sel" style="color:black" onchange="mainacct()"></select>
|
||||||
id="main-acct-sel"
|
|
||||||
class="acct-sel"
|
|
||||||
style="color:black"
|
|
||||||
onchange="mainacct()"
|
|
||||||
></select>
|
|
||||||
<label></label>
|
<label></label>
|
||||||
</div>
|
</div>
|
||||||
<ul id="domain-list" class="collection transparent"></ul>
|
<ul id="domain-list" class="collection transparent"></ul>
|
||||||
|
@ -151,4 +129,5 @@
|
||||||
<script type="text/javascript" src="../../js/tl/date.js"></script>
|
<script type="text/javascript" src="../../js/tl/date.js"></script>
|
||||||
<script>$('body').addClass(localStorage.getItem('platform'))</script>
|
<script>$('body').addClass(localStorage.getItem('platform'))</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user