phpoauthlib2

phpoauthlib2 Git Source Tree


Root/OAuthDataProvider.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
 
namespace phpoauthlib2;
 
require "ccurl.php";
 
use phpoauthlib2\ccurl;
 
class OAUTH_SCOPES {
    const EMAIL = "EMAIL";
}
 
class OAuthDataProvider {
    protected $version = "2.0";
    protected $name = "undefined";
    protected $responseType = "code";
    protected $header = "Authorization: Bearer";
    protected $profile = "";
    protected $dialog = "";
    protected $nonce = null;
    protected $accessToken = null;
 
    protected $state = "";
    protected $redirectURL = "";
    protected $scope = "";
    protected $clientId = "";
    protected $client_secret = "";
 
    protected $request = null;
    protected $profileData = [];
 
    public function __construct($profile, $dialog, $accessToken, $request, $header="Authorization: Bearer") {
        $this->profile = $profile;
        $this->dialog = $dialog;
        $this->accessToken = $accessToken;
        $this->header = $header;
        $this->request = $request;
    }
 
    public function getLoginUrl() {
        $urlBuilder = [];
        $urlBuilder[] = "client_id=" . $this->clientId;
        $urlBuilder[] = "response_type=" . $this->responseType;
        $urlBuilder[] = "scope=" . $this->scope;
        $urlBuilder[] = "state=" . $this->state;
        $urlBuilder[] = "redirect_uri=" . urlencode($this->redirectURL);
        return $this->dialog . "?" . implode("&", $urlBuilder);
    }
 
    protected function getToken() {
        $tokenBuilder = [];
        $tokenBuilder["client_id"] = $this->clientId;
        $tokenBuilder["client_secret"] = $this->client_secret;
        $tokenBuilder["grant_type"] = "authorization_code";
        $tokenBuilder["redirect_uri"] = htmlspecialchars($this->redirectURL);
        $tokenBuilder["code"] = $this->request["code"];
        $curl = new ccurl($this->accessToken);
        $curl->setPost($tokenBuilder);
        $curl->createCurl();
        return (string)$curl;
    }
 
    protected function parseToken() {
        $token = $this->getToken();
        $convertedToken = json_decode($token, true);
        if (!$convertedToken) {
            $realToken = $token;
        } else {
            $realToken = $convertedToken["access_token"];
        }
 
        return $realToken;
    }
 
    public function getProfile() {
        $token = $this->parseToken();
 
        $profileUrl = $this->profile . "=" . $token;
        $curl = new ccurl($profileUrl);
        $curl->addHeader($this->header . " " . $token);
        $curl->createCurl();
        $this->profileData = json_decode((string)$curl, true);
        return (string)$curl;
    }
 
    public function getEmail() {
        return null;
    }
 
    public function getFirstName() {
        return null;
    }
 
    public function getLastName() {
        return null;
    }
 
    public function getGender() {
        return null;
    }
 
    public function getId() {
        return null;
    }
 
    public function getRawProfile() {
        return $this->profileData;
    }
 
    public function getSource() {
        return null;
    }
}

Archive Download this file

Branches

Number of commits:
Page rendered in 0.36776s using 11 queries.