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