From 0a72d2ed2f666e152db61142389fb614009e82a7 Mon Sep 17 00:00:00 2001 From: "mb@mb" Date: Tue, 4 Dec 2018 22:53:18 +0100 Subject: [PATCH] first push to the git --- .gitignore | 2 + README.md | 6 ++- static/icons/icon.jpg | Bin 0 -> 2826 bytes tada.py | 101 +++++++++++++++++++++++++++++++++++++++ templates/actor.json | 22 +++++++++ templates/webfinger.json | 11 +++++ 6 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 static/icons/icon.jpg create mode 100644 tada.py create mode 100644 templates/actor.json create mode 100644 templates/webfinger.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13faf01 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pem +__pycache__ diff --git a/README.md b/README.md index cf38115..503849e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ -# ap.flask +# AP test in Flask + +This is a testing area! :) + -an ActivityPub testing area in Flask \ No newline at end of file diff --git a/static/icons/icon.jpg b/static/icons/icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..adb433873dfe1f81648809235045ef4a299f7e7c GIT binary patch literal 2826 zcmeHIZA@Eb6n^e)%e|H|?u8B-Qp#OdO*2`n6J8R-n~Av{XBG)@H){+8KWbv(y#hmIE*jyE?|0=$E;(xKy0hFf*a zdQl>s@hJIp5%xv9`ltp?SSOCQ?v{sXcWZwMG@%+5P|%7#>_r!Pv6=R6;w*FA7A>wG z`zR(tYYa~zP7xjGq}Woj_91~b+S|$AMo$-ckTCAq4j7y!+PAWN)Uu-%uw7Es`AvXu z47f3%s*A&_dSe8zoCC&>81eg#5S_n~J!#l{ZvnZ_1D}o=w$^un&xm8!&#`bktleXw zm2YncuAcyMb^-aswf(XGdamM6(~m*kQb&I?}VEHbB_MghGu94p@tP9VFB%qb@vZ_QGFgu}vt zmn;%}eP@MNE*o*ThlbMJ?fx_qwxyfyZt@R$4-K0wLpRG}Q?i#6j)azxv48M_cic4b zus>&~;ktzE849$gc_Bk2|B2p3p3%yS75>_l&PsBd`8 z^6!ew#7Kt7O~XdT8IUENR}0OPQ%adKd`Pn-((G|I-rc}FRL9bMYp=81%1vv} zlp{95z%z?i$ISG~uS-V@GY@SeozPZ>bIN`?Ia~VC*K718=Cf9v!m9R{c}Ra*GFY}>dO20oQ+XZA z7h+ij%AT`gT$CoDRBTzx03&3XfrcG3XLNiYjaH$Y`fDd67FwA&s$<}ru@78j$NtGr~2mhB82H5NEk+koC=e2*Qj6WGtj8n=2q22u&ee`2d zF8zJVYa$yDzbc!^', methods=['GET']) +def return_actor(actor): + """ This returns the actor.json object when somebody in the + Fediverse searches for this user. It returns the paths of + this user's inbox, its preferred username and the user's public key. + And also a profile icon (image) now! :) """ + + preferredUsername = actor # but could become a custom username, set by the user, stored in the database + # this preferredUsername doesn't show up yet in Mastodon ... + + json = flask.render_template('actor.json', actor=actor, preferredUsername=preferredUsername, publicKey=publicKey(), domain=DOMAIN) # actor = alice + resp = flask.Response(json, status=200, mimetype='application/json') + return resp + +@APP.route('/inspect') +def inspect(): + return flask.Response(b'

'.join(INBOX), status=200) + +@APP.route('/users//inbox', methods=['GET', 'POST']) +def inbox(actor): + """ To post to this inbox, you could use curl: + $ curl -d '{"key" : "value"}' -H "Content-Type: application/json" -X POST http://localhost:5001/users/test/inbox + + Or, with an actual Mastodon follow request: + $ curl -d '{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":{"@id":"as:movedTo","@type":"@id"},"Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","focalPoint":{"@container":"@list","@id":"toot:focalPoint"},"featured":{"@id":"toot:featured","@type":"@id"},"schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value"}],"id":"https://post.lurk.org/02d04ed5-dda6-48f3-a551-2e9c554de745","type":"Follow","actor":"https://post.lurk.org/users/manetta","object":"https://ap.virtualprivateserver.space/users/test","signature":{"type":"RsaSignature2017","creator":"https://post.lurk.org/users/manetta#main-key","created":"2018-11-28T16:15:35Z","signatureValue":"XUdBg+Zj9pkdOXlAYHhOtZlmU1Jdt63zwh2cXoJ8E8C1C+KvgGilkyfPTud9VNymVwdUQRl+YEW9KAZiiGaHb9H+tdVUr9BEkuR5E/tGehbMZr1sakC+qPehe4s3bRKEpJjTTJnTiSHaW7V6Qvr1u6+MVts6oj32az/ixuB/CfodSr3K/K+jZmmOl6SIUqX7Xg7xGwOxIsYaR7g9wbcJ4qyzKcTPZonPMsONq9/RSm3SeQBo7WO1FKlQiFxVP/y5eFaFP8GYDLZyK7Nj5kDL5TannfEpuF8f3oyTBErQhcFQYKcBZNbuaqX/WiIaGjtHIL2ctJe0Psb5Nfshx4MXmQ=="}}' -H "Content-Type: application/json" -X POST http://localhost:5001/users/test/inbox + """ + + if flask.request.method == 'GET': + return '''This has been a {} request.
+ It came with the following header:

{}

+ You have searched for the actor {}.
+ This is {}'s shared inbox:

{}'''.format(flask.request.method, flask.request.headers, actor, DOMAIN, str(INBOX)) + + if flask.request.method == 'POST': + INBOX.append(flask.request.data) + return flask.Response(status=200) + +if __name__ == '__main__': + APP.debug=True + APP.run(port=5001) \ No newline at end of file diff --git a/templates/actor.json b/templates/actor.json new file mode 100644 index 0000000..2a59d26 --- /dev/null +++ b/templates/actor.json @@ -0,0 +1,22 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1" + ], + + "id": "{{ domain }}/users/{{ actor }}", + "type": "Person", + "preferredUsername": "{{ preferredUsername }}", + "inbox": "{{ domain }}/users/{{ actor }}/inbox", + + "publicKey": { + "id": "{{ domain }}/users/{{ actor }}#main-key", + "owner": "{{ domain }}/users/{{ actor }}", + "publicKeyPem": "{{ publicKey }}" + }, + "icon": { + "type": "Image", + "mediaType": "image/jpg", + "url": "https://ap.virtualprivateserver.space/static/icons/icon.jpg" + } +} \ No newline at end of file diff --git a/templates/webfinger.json b/templates/webfinger.json new file mode 100644 index 0000000..1f7fa10 --- /dev/null +++ b/templates/webfinger.json @@ -0,0 +1,11 @@ +{ + "subject": "{{ query }}", + + "links": [ + { + "rel": "self", + "type": "application/activity+json", + "href": "{{ domain }}/users/{{ actor }}" + } + ] +} \ No newline at end of file