Difference between revisions of "CMU OAUTH PHP CLASS"

From CMU ITSC Network
Line 152: Line 152:
 
|object getUserInfo(string $accessToken)
 
|object getUserInfo(string $accessToken)
 
|}
 
|}
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 164: Line 163:
  
 
{| class="wikitable"
 
{| class="wikitable"
|+ style="text-align:left;"|Return Values
+
|+ style="text-align:left;"| Return Values
 +
|-
 +
| object
 
|-
 
|-
| no return value
+
|<pre>{
 +
  "status": true,
 +
  "data": {
 +
    "timestamp": "2017-03-31T17:30:55.7933253+07:00",
 +
    "itaccount_name": "jon_s",
 +
    "citizen_id": "1111111111111",
 +
    "student_id": "520510999",
 +
    "prefix": {
 +
      "en_US": "Mr.",
 +
      "th_TH": "นาย"
 +
    },
 +
    "first_name": {
 +
      "en_US": "JON",
 +
      "th_TH": "จอน"
 +
    },
 +
    "last_name": {
 +
      "en_US": "SNOW",
 +
      "th_TH": "สโนว์"
 +
    },
 +
    "organization": {
 +
      "code": "05",
 +
      "name": {
 +
        "en_US": "Faculty of Science",
 +
        "th_TH": "คณะวิทยาศาสตร์"
 +
      }
 +
    },
 +
    "itaccount_type": {
 +
      "id": "AlumAcc",
 +
      "en_US": "Alumni Account",
 +
      "th_TH": "นักศึกษาเก่า"
 +
    }
 +
  }
 +
}</pre>
 
|}
 
|}
  

Revision as of 11:36, 24 September 2017

Method

Constructor

Set Client ID, Client Secret, Redirect URI

Description
__construct([string $appId, string $clientSecret, string $redirectURI])
Parameters
name description
appId cmu oauth Client ID
clientSecret cmu oauth Client Secret
redirectURI cmu oauth Redirect URI
Return Values
no return value

setAppId

set Client ID

Description
setAppId(string $appid)
Parameters
name description
appid cmu oauth Client ID
Return Values
no return value

setAppSecret

Set Client Secret

Description
setAppSecret(string $appSecret)
Parameters
name description
appSecret cmu oauth Client Secret
Return Values
no return value

setCallbackUri

Set Redirect URI

Description
setCallbackUri(string $uri)
Parameters
name description
uri Application Callback / Redirect URI
Return Values
no return value

initOauth

Initial redirect to CMU Oauth for authorization.

Description
initOauth()
Parameters
no parameter
Return Values
no return value

getAccessToken

Get user's authorized access token.

Description
object getAccessToken(string $code)
Parameters
name description
code code that parse by CMU Oauth to redirect URI.
Return Values
object
{
  "access_token": "66822448858031556636", 
  "expires_in": 3600, 
  "refresh_token": "23178027621214615262"
}

getUserInfo

Get user's information by user's authorized access token.

Description
object getUserInfo(string $accessToken)
Parameters
name description
accessToken user's authorized access token
Return Values
object
{
  "status": true,
  "data": {
    "timestamp": "2017-03-31T17:30:55.7933253+07:00",
    "itaccount_name": "jon_s",
    "citizen_id": "1111111111111",
    "student_id": "520510999",
    "prefix": {
      "en_US": "Mr.",
      "th_TH": "นาย"
    },
    "first_name": {
      "en_US": "JON",
      "th_TH": "จอน"
    },
    "last_name": {
      "en_US": "SNOW",
      "th_TH": "สโนว์"
    },
    "organization": {
      "code": "05",
      "name": {
        "en_US": "Faculty of Science",
        "th_TH": "คณะวิทยาศาสตร์"
      }
    },
    "itaccount_type": {
      "id": "AlumAcc",
      "en_US": "Alumni Account",
      "th_TH": "นักศึกษาเก่า"
    }
  }
}

Examples

Download

cmu.oauth.class.php.zip

Reference

https://oauth.cmu.ac.th
https://tools.ietf.org/html/rfc6749