shrub/lib/oauth1.hoon

61 lines
1.5 KiB
Plaintext
Raw Normal View History

2016-03-08 00:42:23 +03:00
:: OAuth 1.0 %authorization header
::
:::: /hoon/oauth1/lib
::
|%
++ keys
$: con/{tok/@t sec/@t} :: user key pair
acc/{tok/@t sec/@t} :: app key pair
2016-03-07 22:05:37 +03:00
==
2016-03-09 06:49:58 +03:00
++ join :: between every pair
|= {a/tape b/wall} ^- tape
?~(b b |-(?~(t.b i.b :(weld i.b a $(b t.b)))))
::
:: query string in oauth1 'k1="v1", k2="v2"' form
++ to-header
|= a/quay ^- tape
%+ join ", "
(turn a |=({k/@t v/@t} `tape`~[k '="' v '"'])) :: normalized later
::
:: partial tail:earn for sorting
++ encode-pairs
|= a/quay ^- (list tape)
%+ turn a
|= {k/@t v/@t} ^- tape
:(weld (urle (trip k)) "=" (urle (trip v)))
2016-03-08 00:42:23 +03:00
--
::
::::
::
|= $: med/meth
2016-03-09 06:49:58 +03:00
url/purl
quy/quay
2016-03-08 00:42:23 +03:00
key/keys
2016-03-09 05:50:14 +03:00
now/time
eny/@
2016-03-08 00:42:23 +03:00
==
^- @t
2016-03-09 06:49:58 +03:00
=+ ^- aut-quy/quay
:~ 'oauth_consumer_key'^tok.con.key
'oauth_nonce'^(scot %uw (shaf %non eny))
'oauth_signature_method'^'HMAC-SHA1'
'oauth_timestamp'^(rsh 3 2 (scot %ui (unt now)))
'oauth_token'^tok.acc.key
'oauth_version'^'1.0'
==
2016-03-08 00:42:23 +03:00
=+ ^= bas
^- tape
2016-03-09 06:49:58 +03:00
=+ hds=(sort (encode-pairs (weld quy aut-quy)) aor)
%+ join "&"
:~ (trip (cuss (trip `@t`med)))
(urle (earn url))
(urle (join "&" hds))
2016-03-08 00:42:23 +03:00
==
2016-03-09 06:49:58 +03:00
=+ sky=(crip :(weld (urle (trip sec.con.key)) "&" (urle (trip sec.acc.key))))
2016-03-08 00:42:23 +03:00
=+ sig=`tape`(sifo (swap 3 (hmac (swap 3 sky) (crip bas))))
%- crip
2016-03-09 06:49:58 +03:00
%+ weld "OAuth "
%+ to-header
'oauth_signature'^(crip (urle sig))
aut-quy