DokuWiki

It's better when it's simple

User Tools

Site Tools


auth:ning

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
auth:ning [2013-03-01 09:48] – [Installation] 210.55.240.39auth:ning [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-====== Ning authentication  ====== 
  
-===== What does it do? ===== 
- 
-It authenticates users by logging into a Ning community. 
- 
-===== Installation ===== 
- 
-Paste the code into "inc/auth/ning.class.php" and replace 
-  * myningnetwork.ning.com to your domain 
-  * first@example.com and second@example.com to the admin users email 
- 
-Then add the following line to "conf/local.php": 
-  $conf['authtype'] = 'ning'; 
- 
-Make sure that the file does not contain empty lines at the beginning and at the end, otherwise you will get PHP warnings. 
- 
-**NOTE** 
- 
-Username and password are sent as plaintext.  To use a secure SSL connection modify checkDomain function by setting $url to use https and adding a user agent to the curl options:  
- 
-        function checkDomain($domain) { 
-            $url = "https://$domain/main/external/info?format=serialize"; 
-            $curl = curl_init($url); 
- 
-            curl_setopt ($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");   // set user agent to allow SSL to work 
- 
- 
-===== Code ===== 
- 
-<file php ning.class.php> 
-<?php 
-/** 
- * auth/ning.class.php 
- * 
- * ning authorization class 
- * 
- * @author    Norbert Mocsnik 
- */ 
- 
-define('DOKU_AUTH', dirname(__FILE__)); 
-require_once(DOKU_AUTH . '/basic.class.php'); 
- 
-class NingConfig { 
-    function getDomain() { 
-        return 'myningnetwork.ning.com'; 
-    } 
- 
-    function getAdmins() { 
-        return array( 
-            'first@example.com', 
-            'second@example.com' 
-            ); 
-    } 
-} 
- 
-/** 
-  Ning Authentification API and plugin configuration options. 
-  Extracted from the Ning Auth API for Wordpress. 
- */ 
-class NingIdApi { 
-    /** 
-      Checks whether domain is valid. 
-     * 
-      @param      $domain     string      Domain name (w/o schema and path) 
-      @return     boolean 
-     */ 
-    function checkDomain($domain) { 
-        $url = "http://$domain/main/external/info?format=serialize"; 
-        $curl = curl_init($url); 
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
-        $result = curl_exec($curl); 
-        if ($result && is_array($info = unserialize($result)) && $info['version']) { 
-            return true; 
-        } 
-        return false; 
-    } 
- 
-    /** 
-      Authorizes ning user and returns some information about him/her. 
-      Returns array with user information or NULL if authentification fails 
-     * 
-      @param      $domain     string      Ning network domain (w/o schema and path) 
-      @param      $email      string      Screen name or email 
-      @param      $password   string      Password 
-      @return     {name, email, avatar_url} 
-     */ 
-    function authorize($domain, $email, $password) { 
-        $url = "http://$domain/main/external/auth?format=serialize"; 
-        $curl = curl_init($url); 
-        curl_setopt($curl, CURLOPT_POST, true); 
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
-        curl_setopt($curl, CURLOPT_POSTFIELDS, "email=".urlencode($email)."&password=".urlencode($password)); 
-        curl_setopt($curl, CURLOPT_USERAGENT, "botd Mozilla/4.0 (Compatible; Ning Auth API)"); 
-        $result = curl_exec($curl); 
-        if ($result && is_array($info = unserialize($result)) && count($info) && $info['email'] && $info['name']) { 
-            return $info; 
-        } 
-        return NULL; 
-    } 
-} 
- 
-class auth_ning extends auth_basic { 
-    var $ning_name; 
-    var $ning_email; 
-    var $ning_grps; 
- 
-    /** 
-     * Check user+password [ MUST BE OVERRIDDEN ] 
-     * 
-     * Checks if the given user exists and the given 
-     * plaintext password is correct 
-     * 
-     * May be ommited if trustExternal is used. 
-     * 
-     * @author  Norbert Mocsnik 
-     * @return  bool 
-     */ 
-    function checkPass($user,$pass){ 
-        if ($info = NingIdApi::authorize(NingConfig::getDomain(), $user, $pass)) { 
-            $this->ning_name = $info['name']; 
-            $this->ning_email = $info['email']; 
- 
-            $this->ning_grps = array('user'); 
-            if (in_array($user, NingConfig::getAdmins())) { 
-                $this->ning_grps[] = 'admin'; 
-            } 
- 
-            return true; 
-        } 
- 
-        return false; 
-    } 
- 
-    /** 
-     * Return user info [ MUST BE OVERRIDDEN ] 
-     * 
-     * Returns info about the given user needs to contain 
-     * at least these fields: 
-     * 
-     * name string  full name of the user 
-     * mail string  email addres of the user 
-     * grps array   list of groups the user is in 
-     * 
-     * @author  Norbert Mocsnik 
-     * @return  array containing user data or false 
-     */ 
-    function getUserData($user) { 
-        return array( 
-            'name' => $this->ning_name, 
-            'mail' => $this->ning_email, 
-            'grps' => $this->ning_grps 
-        ); 
-    } 
-} 
- 
- 
-?> 
-</file> 
auth/ning.1362127728.txt.gz · Last modified: 2013-03-01 09:48 by 210.55.240.39

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki