From e6c861480138ba871907ed6994d0fb840fd0e77f Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 14 Jul 2016 19:24:15 -0700 Subject: first cut at zot access tokens --- include/security.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'include/security.php') diff --git a/include/security.php b/include/security.php index 212690d91..55e9d906f 100644 --- a/include/security.php +++ b/include/security.php @@ -82,6 +82,39 @@ function authenticate_success($user_record, $login_initial = false, $interactive /* else just return */ } +function atoken_login($atoken) { + if(! $atoken) + return false; + + $xchan = atoken_xchan($atoken); + + $_SESSION['authenticated'] = 1; + $_SESSION['visitor_id'] = $xchan['xchan_hash']; + $_SESSION['atoken'] = $atoken['atoken_id']; + + \App::set_observer($xchan); + + return [ 'atoken' => true ]; +} + + +function atoken_xchan($atoken) { + + return [ + 'xchan_hash' => $atoken['atoken_uid'] . '.' . $atoken['atoken_name'], + 'xchan_network' => 'unknown', + 'xchan_hidden' => 1, + 'xchan_photo_mimetype' => 'image/jpeg', + 'xchan_photo_l' => get_default_profile_photo(300), + 'xchan_photo_m' => get_default_profile_photo(80), + 'xchan_photo_s' => get_default_profile_photo(48) + + ]; + +} + + + /** * @brief Change to another channel with current logged-in account. * -- cgit v1.2.3 From f3eb9af046b155c53a194db6104a24b6d6756072 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 14 Jul 2016 19:43:47 -0700 Subject: more ZAT work --- include/security.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/security.php') diff --git a/include/security.php b/include/security.php index 55e9d906f..c2515a6e1 100644 --- a/include/security.php +++ b/include/security.php @@ -102,6 +102,8 @@ function atoken_xchan($atoken) { return [ 'xchan_hash' => $atoken['atoken_uid'] . '.' . $atoken['atoken_name'], + 'xchan_name' => $atoken['atoken_name'], + 'xchan_addr' => t('guest:') . $atoken['atoken_name'] . '@' . \App::get_hostname(), 'xchan_network' => 'unknown', 'xchan_hidden' => 1, 'xchan_photo_mimetype' => 'image/jpeg', -- cgit v1.2.3 From 397a23499dc64e2abdd2c27ccdf7e059a23dcfff Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 14 Jul 2016 21:28:17 -0700 Subject: make the xchan_hash for the access token location independent --- include/security.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'include/security.php') diff --git a/include/security.php b/include/security.php index c2515a6e1..e345636e7 100644 --- a/include/security.php +++ b/include/security.php @@ -100,18 +100,21 @@ function atoken_login($atoken) { function atoken_xchan($atoken) { - return [ - 'xchan_hash' => $atoken['atoken_uid'] . '.' . $atoken['atoken_name'], - 'xchan_name' => $atoken['atoken_name'], - 'xchan_addr' => t('guest:') . $atoken['atoken_name'] . '@' . \App::get_hostname(), - 'xchan_network' => 'unknown', - 'xchan_hidden' => 1, - 'xchan_photo_mimetype' => 'image/jpeg', - 'xchan_photo_l' => get_default_profile_photo(300), - 'xchan_photo_m' => get_default_profile_photo(80), - 'xchan_photo_s' => get_default_profile_photo(48) - - ]; + $c = channelx_by_n($atoken['atoken_uid']); + if($c) { + return [ + 'xchan_hash' => substr($c['channel_hash'],0,16) . '.' . $atoken['atoken_name'], + 'xchan_name' => $atoken['atoken_name'], + 'xchan_addr' => t('guest:') . $atoken['atoken_name'] . '@' . \App::get_hostname(), + 'xchan_network' => 'unknown', + 'xchan_hidden' => 1, + 'xchan_photo_mimetype' => 'image/jpeg', + 'xchan_photo_l' => get_default_profile_photo(300), + 'xchan_photo_m' => get_default_profile_photo(80), + 'xchan_photo_s' => get_default_profile_photo(48) + + ]; + } } -- cgit v1.2.3