cdb90d030b2c2a52f628a0f07bf1f86d4033b161
[WP-Plugins/glm-member-db.git] /
1 <?php
2 namespace PayPal\Auth\Openid;
3 use PayPal\Common\PPModel;
4 /**
5  * Token grant resource
6  */
7 class PPOpenIdTokeninfo extends PPModel {
8
9                 /**
10                  * OPTIONAL, if identical to the scope requested by the client; otherwise, REQUIRED.
11                  * @param string $scope
12                  */
13                  public function setScope($scope) {
14                         $this->scope = $scope;
15                         return $this;
16                  }
17                 
18                 /**
19                  * OPTIONAL, if identical to the scope requested by the client; otherwise, REQUIRED.
20                  * @return string
21                  */
22                  public function getScope() {
23                         return $this->scope;
24                  }
25                  
26                 /**
27                  * The access token issued by the authorization server.
28                  * @param string $access_token
29                  */
30                  public function setAccessToken($access_token) {
31                         $this->access_token = $access_token;
32                         return $this;
33                  }
34                 
35                 /**
36                  * The access token issued by the authorization server.
37                  * @return string
38                  */
39                  public function getAccessToken() {
40                         return $this->access_token;
41                  }
42                  
43                 /**
44                  * The refresh token, which can be used to obtain new access tokens using the same authorization grant as described in OAuth2.0 RFC6749 in Section 6.
45                  * @param string $refresh_token
46                  */
47                  public function setRefreshToken($refresh_token) {
48                         $this->refresh_token = $refresh_token;
49                         return $this;
50                  }
51                 
52                 /**
53                  * The refresh token, which can be used to obtain new access tokens using the same authorization grant as described in OAuth2.0 RFC6749 in Section 6.
54                  * @return string
55                  */
56                  public function getRefreshToken() {
57                         return $this->refresh_token;
58                  }
59                  
60                 /**
61                  * The type of the token issued as described in OAuth2.0 RFC6749 (Section 7.1).  Value is case insensitive.
62                  * @param string $token_type
63                  */
64                  public function setTokenType($token_type) {
65                         $this->token_type = $token_type;
66                         return $this;
67                  }
68                 
69                 /**
70                  * The type of the token issued as described in OAuth2.0 RFC6749 (Section 7.1).  Value is case insensitive.
71                  * @return string
72                  */
73                  public function getTokenType() {
74                         return $this->token_type;
75                  }
76                  
77                 /**
78                  * The id_token is a session token assertion that denotes the user's authentication status
79                  * @param string $id_token
80                  */
81                  public function setIdToken($id_token) {
82                         $this->id_token = $id_token;
83                         return $this;
84                  }
85                 
86                 /**
87                  * The id_token is a session token assertion that denotes the user's authentication status
88                  * @return string
89                  */
90                  public function getIdToken() {
91                         return $this->id_token;
92                  }
93                  
94                 /**
95                  * The lifetime in seconds of the access token.
96                  * @param integer $expires_in
97                  */
98                  public function setExpiresIn($expires_in) {
99                         $this->expires_in = $expires_in;
100                         return $this;
101                  }
102                 
103                 /**
104                  * The lifetime in seconds of the access token.
105                  * @return integer
106                  */
107                  public function getExpiresIn() {
108                         return $this->expires_in;
109                  }
110                  
111
112         /**
113                  * Creates an Access Token from an Authorization Code.
114                  *
115                  * @path /v1/identity/openidconnect/tokenservice
116                  * @method POST
117                  * @param array $params (allowed values are grant_type, code and redirect_uri)
118                  *                              (optional) grant_type is the Token grant type. Defaults to authorization_code
119                  *                              code is Authorization code previously received from the authorization server
120                  *                              redirect_uri Redirection endpoint that must match the one provided during the 
121                  *                                      authorization request that ended in receiving the authorization code.
122                  * @param PPApiContext $apiContext Optional API Context   
123                  * @return PPOpenIdTokeninfo
124                  */
125                 public static function createFromAuthorizationCode($params, $apiContext=null) {
126                         static $allowedParams = array('grant_type' => 1, 'code' => 1, 'redirect_uri' => 1);
127                         if(is_null($apiContext)) {
128                                 $apiContext = new PPApiContext();
129                         }
130                         
131                         if(!array_key_exists('grant_type', $params)) {
132                                 $params['grant_type'] = 'authorization_code';
133                         }       
134                         
135                         $call = new PPRestCall($apiContext);
136                         $token = new PPOpenIdTokeninfo();
137                         $token->fromJson(
138                                 $call->execute(array('PPOpenIdHandler'),
139                                         "/v1/identity/openidconnect/tokenservice" , "POST", 
140                                         http_build_query(array_intersect_key($params, $allowedParams)),
141                                         array('Content-Type' => 'application/x-www-form-urlencoded')
142                         ));
143                         return $token;
144                 }
145         /**
146                  * Creates an Access Token from an Refresh Token.
147                  *
148                  * @path /v1/identity/openidconnect/tokenservice
149                  * @method POST
150                  * @param array $params (allowed values are grant_type and scope)
151                  *                              (optional) refresh_token refresh token. If one is not passed, refresh token from the current object is used.
152                  *                              (optional) grant_type is the Token grant type. Defaults to refresh_token
153                  *                              scope is an array that either the same or a subset of the scope passed to the authorization request
154                  * @param APIContext $apiContext Optional API Context   
155                  * @return PPOpenIdTokeninfo
156                  */
157                 public function createFromRefreshToken($params, $apiContext=null) {
158                         
159                         static $allowedParams = array('grant_type' => 1, 'refresh_token' => 1, 'scope' => 1);
160                         if(is_null($apiContext)) {
161                                 $apiContext = new PPApiContext();
162                         }
163                                                         
164                         if(!array_key_exists('grant_type', $params)) {
165                                 $params['grant_type'] = 'refresh_token';
166                         }
167                         if(!array_key_exists('refresh_token', $params)) {
168                                 $params['refresh_token'] = $this->getRefreshToken();
169                         }
170                                                 
171                         
172                         $call = new PPRestCall($apiContext);                    
173                         $this->fromJson(
174                                 $call->execute(array('PPOpenIdHandler'), 
175                                         "/v1/identity/openidconnect/tokenservice", "POST",
176                                         http_build_query(array_intersect_key($params, $allowedParams)),
177                                         array('Content-Type' => 'application/x-www-form-urlencoded')
178                         ));
179                         return $this;
180                 }
181 }