Google Groups deletes every answer on my own post... so another try: oauth-module

35 views
Skip to first unread message

Richard Mücke

unread,
Sep 27, 2024, 2:43:02 AM9/27/24
to Xataface
Regarding "How to contribute a sub module for oauth?" I answer in a new thread, because google keeps deleting every singler answer I post. 

Here is the answer:

Thanks Steve. We do have a functionable module.
Maybe someone can use this:

MODULE oauth_azure.php
<?php
class modules_oauth_azure {
    public function __construct() {
        $app = Dataface_Application::getInstance();
        $app->registerEventListener('oauth_fetch_user_data', array($this, 'oauth_fetch_user_data'), false);
        $app->registerEventListener('oauth_extract_user_properties_from_user_data', array($this, 'oauth_extract_user_properties_from_user_data'), false);
    }
   
   
    public function oauth_fetch_user_data($evt) {
        if ($evt->service !== 'azure') {
            return;
        }
        $mod = Dataface_ModuleTool::getInstance()->loadModule('modules_oauth');

        $enc_data = $mod->getOauthToken('azure');
list($header, $payload, $signature) = explode(".", $enc_data);
$plainHeader = base64_decode($header);
$plainPayload = base64_decode($payload);

$data = json_decode($plainPayload, true);
$upn = $data['upn'];
$oid = $data['oid'];
$name = $data['name'];
$email = strtolower($data['upn']);
$evt->out = array("upn" => $upn, "id" => $email, "name" => $name, "email" => $email);
return;
       
    }
   
    public function oauth_extract_user_properties_from_user_data($evt) {
        if ($evt->service !== 'azure') {
            return;
        }
           $evt->out = array(
            'id' => $evt->userData['id'],
            'name' => $evt->userData['name'],
            'upn' => $evt->userData['upn'],
'email' => $evt->userData['email']
);
    }
   
           
}

This is conf.ini:
[_modules]
modules_oauth="modules/Auth/oauth/oauth.php"
modules_oauth_azure="modules/Auth/oauth/oauth_azure.php"

[oauth_azure]
    client_id="clientid"
    client_secret="secret"
scope = openid email profile
    autocreate=1   


This is actions.ini:
[oauth_azure]
    oauth.url="https://login.microsoftonline.com/enter_your_id/oauth2/v2.0/authorize"
    oauth.request_token_url="https://login.microsoftonline.com/enter_your_id/oauth2/v2.0/token"
oauth.url_logout = "https://login.microsoftonline.com/enter_your_id/oauth2/v2.0/logout"
    label="OAUTH-Login"
    category="login_actions"


Best regards
Richard

Richard Mücke

unread,
Sep 27, 2024, 2:43:49 AM9/27/24
to Xataface

Steve Hannah

unread,
Sep 27, 2024, 4:07:48 PM9/27/24
to Xataface
Thanks for sharing this, Richard.  I'm sure this will be helpful to others.  Do you mind if I copy this into a github repo, like with the other modules?  

Richard Mücke

unread,
Sep 28, 2024, 1:20:16 AM9/28/24
to Xataface
Yes, for sure. Please share it.
Thanks.

garr...@gmail.com

unread,
Sep 28, 2024, 9:17:44 AM9/28/24
to Xataface
I also experience the deleted messages when I try to post on my own posts in xataface. They delete right after posting, anyone have a solution? 
Reply all
Reply to author
Forward
0 new messages