diff --git a/lib/oauth2.hoon b/lib/oauth2.hoon index 196ad31013..0bdff1eeb4 100644 --- a/lib/oauth2.hoon +++ b/lib/oauth2.hoon @@ -30,6 +30,7 @@ |% ++ token ?(~ @t) ++ keys cord:,[cid=@t cis=@t] +++ core-move |*(a=* $&([sec-move _a] sec-move)) ++ decode-keys :: XX from bale w/ typed %jael |=(key=keys ((hard ,[cid=@t cis=@t ~]) (lore key))) -- @@ -107,13 +108,18 @@ ++ expires-in 'expires_in'^ni:jo ++ access-token 'access_token'^so:jo ++ refresh-token 'refresh_token'^so:jo -++ bak-parse-access +++ bak-save-access + |* [done=* handle=$+(cord:token *)] :: $+(token _done) + %- (bak-parse done access-token ~) + |=(tok=token [[%redo ~] (handle tok)]) +:: +++ bak-parse |* [done=* parse=(pole ,[span fist]:jo)] - |= handle=$+(_?~(parse *token [*token (need *(ot:jo parse))]) _done) - |= a=httr ^- [sec-move _done] - :- [%redo ~] - ?: (bad-response p.a) done :: handle 4xx? - (handle (grab-json a (ot:jo access-token parse))) + =+ fin=$&([sec-move _done] sec-move) + |= handle=$+(_?~(parse ~ (need *(ot:jo parse))) fin) + |= a=httr ^- fin + ?: (bad-response p.a) [%redo ~] :: handle 4xx? + (handle (grab-json a (ot:jo parse))) :: :: ++ bak-parse-refresh :: |= a=httr ^- [sec-move _+>] diff --git a/sec/com/facebook/graph.hoon b/sec/com/facebook/graph.hoon index 8a2b087868..31ac82edf6 100644 --- a/sec/com/facebook/graph.hoon +++ b/sec/com/facebook/graph.hoon @@ -6,16 +6,15 @@ =+ aut=(oauth2 - /'v2.3'/oauth/'access_token') |_ [bal=(bale keys.aut) access-token=token.aut] ++ auth ~(. aut bal /'user_about_me'/'user_posts') -++ out (out-quay:auth 'access_token'^access-token) +++ out + ~& access-token + (out-quay:auth 'access_token'^access-token) ++ in in-code:auth ++ bak - |= res=httr - =+ a=auth - ?: (bad-response.a p.res) [%redo ~] - =+ ^- [access-token=@t expires-in=@u] - (grab-json.a res (ot:jo access-token expires-in ~):a) + %- (bak-parse:auth . access-token.aut expires-in.aut ~) + |= [access-token=@t expires-in=@u] ?: (lth expires-in ^~((div ~d7 ~s1))) :: short-lived token - (toke-req:a 'fb_exchange_token' fb-exchange-token/access-token ~) + (toke-req:auth 'fb_exchange_token' fb-exchange-token/access-token ~) [[%redo ~] ..bak(access-token access-token)] ::++ wipe !! -- diff --git a/sec/com/slack.hoon b/sec/com/slack.hoon index f0cc93e08b..0c5edd8f31 100644 --- a/sec/com/slack.hoon +++ b/sec/com/slack.hoon @@ -7,5 +7,5 @@ ++ aut ~(. ^aut +<- /client/admin) ++ out (out-quay:aut 'token'^tok) ++ in in-code:aut -++ bak ((bak-parse-access:aut . ~) |=(tok=token:aut +>(tok tok))) +++ bak (bak-save-access:aut . |=(tok=token:aut +>(tok tok))) --