Imagehoster
Imagehoster is opensource community software that helps you to proxy user uploaded images and allows you to create easy user authenticated image uploads with extra benefits (rate limiting based on reputation, blacklist, etc.)
There are couple instance of imagehosters run by different teams, https://images.hive.blog and https://images.ecency.com separately maintained/hosted instance of Imagehoster. You can also start your own instance easily by following Readme and Devportal guides.
If user login to your app with Hivesigner, you can verify user and accept their uploads by utilizing techniques used by Imagehoster, above instances does that and verify access_token for uploads.
POST /hs/:accesstoken
Above endpoint takes access_token and verifies if it was created by same app, in above instances, @hive.blog and @ecency.app, when you setting up your own instance of imagehoster, your users in your app will be able to verify and upload images to your instance. Below is code section to show how verification is done.
1
// take access token from url params
2
const token = ctx.params['accesstoken']
3
//decode access token
4
const decoded = Buffer.from(b64uToB64(token), 'base64').toString()
5
// parse it into object
6
const tokenObj = JSON.parse(decoded)
7
const signedMessage = tokenObj.signed_message
8
if (
9
tokenObj.authors
10
&& tokenObj.authors[0]
11
&& tokenObj.signatures
12
&& tokenObj.signatures[0]
13
&& signedMessage
14
&& signedMessage.type
15
&& ['login', 'posting', 'offline', 'code', 'refresh']
16
.includes(signedMessage.type)
17
&& signedMessage.app
18
) {
19
// get username from access_token
20
const username = tokenObj.authors[0]
21
22
let account = {
23
name: '',
24
reputation: 0,
25
}
26
// initialize Hivesigner with user access_token and app_account from imagehoster config
27
const cl = new hivesigner.Client({
28
app: UPLOAD_LIMITS.app_account,
29
accessToken: token,
30
})
31
32
await cl.me(function (err: any, res: any) {
33
if (!err && res) {
34
account = res.account
35
APIError.assert(account, APIError.Code.NoSuchAccount)
36
37
ctx.log.warn('uploading app %s', signedMessage.app)
38
APIError.assert(username === account.name, APIError.Code.InvalidSignature)
39
// user access_token should have same signed app account as imagehoster defined app account.
40
APIError.assert(signedMessage.app === UPLOAD_LIMITS.app_account, APIError.Code.InvalidSignature)
41
APIError.assert(res.scope.includes('comment'), APIError.Code.InvalidSignature)
42
// check if user has authorized posting authority to app_account
43
if (account && account.name) {
44
['posting', 'active', 'owner'].forEach((type) => {
45
account[type].account_auths.forEach((key: string[]) => {
46
if (
47
!validSignature
48
&& key[0] === UPLOAD_LIMITS.app_account
49
) {
50
validSignature = true;
51
}
52
});
53
});
54
}
55
}
56
});
57
}
Copied!
This is simple verification method use only app accounts to verify access_token and validity of user.
Export as PDF
Copy link