urbit/sec/com/googleapis/www.hoon

57 lines
1.4 KiB
Plaintext
Raw Normal View History

2016-03-04 23:27:54 +03:00
:: Test url +https://www.googleapis.com/oauth2/v1/userinfo
::
:::: /hoon/www/googleapis/com/sec
::
2016-01-27 04:44:14 +03:00
/+ oauth2
::
::::
::
|%
2016-02-19 23:33:56 +03:00
++ user-state {ber/token ref/refresh}:oauth2
2016-01-28 00:58:28 +03:00
++ suffix-email
%+ cook welp
;~ plug
(star ;~(less pat prn))
;~(pose (plus prn) (easy "@gmail.com"))
==
::
++ auth-usr
2016-02-19 23:33:56 +03:00
|= usr/iden
2016-01-28 00:58:28 +03:00
=+ lon=(fall (slaw %t usr) usr)
2016-01-27 04:44:14 +03:00
=< .(state-usr &)
%- oauth2
:_ exchange='https://www.googleapis.com/oauth2/v4/token'
^= dialog
%* . (need (epur 'https://accounts.google.com/o/oauth2/v2/auth'))
r
%- fass:oauth2
:~ login-hint+?~(lon '' (crip (rash lon suffix-email)))
access-type+%offline
response-type+%code
prompt+%consent
==
2016-01-16 02:30:15 +03:00
==
--
!:
2016-01-16 02:30:15 +03:00
::::
::
2016-02-19 23:33:56 +03:00
|_ {bal/(bale keys:oauth2) user-state}
++ auth-re ~(. (re:auth .) ref |=(a/_ref +>(ref a)))
2016-02-17 05:21:45 +03:00
++ auth ~(. (auth-usr usr.bal) bal (scopes 'userinfo.email' 'plus.me' ~))
2016-01-27 04:44:14 +03:00
++ scopes
2016-02-19 23:33:56 +03:00
=+ scope=|=(b/@ta (endpoint:oauth2 dom.bal /auth/[b]))
2016-02-24 06:49:17 +03:00
|=(a/(list @ta) ['https://mail.google.com' (turn a |=(b/@ta (crip (earn (scope b)))))])
2016-01-27 04:44:14 +03:00
::
++ out (out-fix-expired:auth-re (out-math:auth ber))
2016-02-19 23:33:56 +03:00
++ res |=(a/httr ((res-handle-refreshed:auth-re save-access res-give:auth) a))
2016-02-17 05:21:45 +03:00
::
2016-02-19 23:33:56 +03:00
++ save-access |=(a/cord:[token:oauth2] +>(ber a))
2016-01-27 04:44:14 +03:00
::
++ in
2016-02-19 23:33:56 +03:00
|= a/quay
(in-code:auth a)
2016-02-19 23:33:56 +03:00
++ bak |=(a/httr ((bak-save-tokens:auth-re save-access) a))
2016-02-24 06:49:17 +03:00
++ upd *user-state
2016-02-11 21:27:32 +03:00
::
--