Hey,Since I had already used annotatorjs, I have a store implementation done in C# for that. I can share the git repo link here if some one is interested, it just needs to be rectified a little as of now.I will try implementing a store backened for H on similar lines and will update here. Will be tracing calls made by the script while creating and searching for annotations and base my store APIs on those.Thanks,Apurva Jalit
--
You received this message because you are subscribed to the Google Groups "dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dev+uns...@list.hypothes.is.
To post to this group, send email to d...@list.hypothes.is.
To view this discussion on the web visit https://groups.google.com/a/list.hypothes.is/d/msgid/dev/9e65e358-3814-4f15-9cc5-94d13d227bed%40list.hypothes.is.
Hey,While trying to create a C# backened, I figured out what all APIs I need to consume at the backend to support browser extension. One of them is "token". I can see in the app.js file how a token is parsed and used but I am not able to figure out how to generate a token in the backend. The function call request.create_token_response() creates a token I suppose, but can you help me understand how does it do that? Is there any standard it follows?Thanks,Apurva Jalit
Yes. The token is a JWT. Annotator has documentation for this.
On May 20, 2015 8:39 AM, "Apurva Jalit" <apurva...@gmail.com> wrote:
Hey,
While trying to create a C# backened, I figured out what all APIs I need to consume at the backend to support browser extension. One of them is "token". I can see in the app.js file how a token is parsed and used but I am not able to figure out how to generate a token in the backend. The function call request.create_token_response() creates a token I suppose, but can you help me understand how does it do that? Is there any standard it follows?
Thanks,Apurva Jalit
On May 25, 2015 4:53 AM, "Apurva Jalit" <apurva...@gmail.com> wrote:
>
> After going through the different API requests made by the hypothes.is browser extension, I have certain queries as follows. Understanding them would help me go ahead with the implementation in synch with the present framework.
> Authentication and the user management: I can see the three parameters being used for these: X-csrf token, session and client-ID. Can you just help me understand what is the role of each, which component creates it (browser extension or backened server) and a brief about how it is used in the whole framework.
X-CSRF-Token
This is a standard cross site request forgery token. We abuse it a little bit by sending the token in responses to authentication and session requests, since cookie policies might prevent us from reading it from the cookie value.
Session is the session id.
X-Client-Id
This uniquely identifies this page view so that real time events don't echo back over the WebSocket to the client that caused them. It's not critical, just a performance hack.
> I can see a section for facebook and twitter in the annotation data. What is that exactly used for? (Just to understand what to do with it)
Not used for anything right now, except for fields that stand in for canonical URLs.
> If possible can you share with me complete data types of the parameters exchanged between the backend and the extension code for various API calls.
The core API is the same as Annotator's storage plugin, which is documented in h and Annotator and annotator-store.
The rest is to be considered unstable.
#!/usr/local/bin/python3.4
import os
import glob
import sys
import argparse
import json
import requests
from hypothesisapi import *
from rdflib import Graph, RDF
from rdflib.namespace import Namespace, FOAF
OA = Namespace('http://www.w3.org/ns/oa#')
parser = argparse.ArgumentParser()
parser.add_argument('-u', dest='user', action='store',
default='arXiv', help='hypothes.is user (default: arXiv)')
parser.add_argument('-p', dest='password', action='store',
help='hypothes.is password')
parser.add_argument('-d', dest='trackbacks_dir', action='store',
default='/data/shared/data/trackbacks',
help='directory with turtle (.ttl) trackback files;' +
'default=/data/shared/data/trackbacks')
args = parser.parse_args()
# Set up Hypothes.is config
H = API(args.user, args.password)
H.login()
#APP_URL = "https://hypothes.is/app"
API_URL = "https://hypothes.is/api/annotations"
#Read in trackbacks and POST them to hypothes.is:
for tfile in glob.glob(args.trackbacks_dir + "/*.ttl"):
G = Graph()
G.parse(tfile, format="n3")
for trackback, _, article in G.triples( (None, OA.hasTarget, None) ):
for _, _, comment in G.triples( (trackback, OA.hasBody, None) ):
print(article)
print(comment)
payload = {
"user" : "acct:%s...@hypothes.is" % args.user,
"uri" : article,
"text" : comment,
"permissions": {
"read" : ["group:__world__"],
"update": ["acct:%s...@hypothes.is" % args.user],
"delete": ["acct:%s...@hypothes.is" % args.user],
"admin" : ["acct:%s...@hypothes.is" % args.user]
}
}
headers = {'Authorization': 'Bearer ' + H.token.decode("utf-8"),
'X-Annotator-Auth-Token' : H.token.decode("utf-8"),
'x-csrf-token' : H.csrf_token
}
print(json.dumps(payload))
r = requests.post(API_URL, headers=headers, data=payload)
print(r.status_code)
print(r.text)
Sorry for my previous mails. I found out the issue.Annotation ID was not set and hence the problem. I am sorry for sending out emails for these stupid issues!Thanks,Apurva JalitOn Thu, May 28, 2015 at 1:37 PM, Apurva Jalit <apurva...@gmail.com> wrote:I just noticed that the token generated by me has an invalid signature. Could this be the reason behind the problem? Any kind of validation on the client side for that?But I think I can safely assume that this should not be a problem since it is letting me create a note. But just thought I would bring it to your notice in case this helps.Thanks,Apurva JalitOn Thu, May 28, 2015 at 12:02 PM, Apurva Jalit <apurva...@gmail.com> wrote:I am facing a problem when trying to edit a note created by the user who is currently logged in.I am attaching with this mail all the XHR requests made the h chrome extension to my backend. As you can see, in search we have 1 note for the given page. It is created by the user "aps" and it is the same user currently logged in also. But that note on the sidebar is not providing me with an option to edit.In the same context, can you clarify what does the 'acct:' prefix added to the username mean here? Am I abusing it and causing this issue here? What do we look for in a note to identify which user has created it so as to identify whether current user can be given an option to edit/delete the note?Thanks,Apurva Jalit