2 namespace PayPal\Auth\Openid;
3 use PayPal\Common\PPModel;
7 class PPOpenIdTokeninfo extends PPModel {
10 * OPTIONAL, if identical to the scope requested by the client; otherwise, REQUIRED.
11 * @param string $scope
13 public function setScope($scope) {
14 $this->scope = $scope;
19 * OPTIONAL, if identical to the scope requested by the client; otherwise, REQUIRED.
22 public function getScope() {
27 * The access token issued by the authorization server.
28 * @param string $access_token
30 public function setAccessToken($access_token) {
31 $this->access_token = $access_token;
36 * The access token issued by the authorization server.
39 public function getAccessToken() {
40 return $this->access_token;
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
47 public function setRefreshToken($refresh_token) {
48 $this->refresh_token = $refresh_token;
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.
56 public function getRefreshToken() {
57 return $this->refresh_token;
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
64 public function setTokenType($token_type) {
65 $this->token_type = $token_type;
70 * The type of the token issued as described in OAuth2.0 RFC6749 (Section 7.1). Value is case insensitive.
73 public function getTokenType() {
74 return $this->token_type;
78 * The id_token is a session token assertion that denotes the user's authentication status
79 * @param string $id_token
81 public function setIdToken($id_token) {
82 $this->id_token = $id_token;
87 * The id_token is a session token assertion that denotes the user's authentication status
90 public function getIdToken() {
91 return $this->id_token;
95 * The lifetime in seconds of the access token.
96 * @param integer $expires_in
98 public function setExpiresIn($expires_in) {
99 $this->expires_in = $expires_in;
104 * The lifetime in seconds of the access token.
107 public function getExpiresIn() {
108 return $this->expires_in;
113 * Creates an Access Token from an Authorization Code.
115 * @path /v1/identity/openidconnect/tokenservice
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
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();
131 if(!array_key_exists('grant_type', $params)) {
132 $params['grant_type'] = 'authorization_code';
135 $call = new PPRestCall($apiContext);
136 $token = new PPOpenIdTokeninfo();
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')
146 * Creates an Access Token from an Refresh Token.
148 * @path /v1/identity/openidconnect/tokenservice
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
157 public function createFromRefreshToken($params, $apiContext=null) {
159 static $allowedParams = array('grant_type' => 1, 'refresh_token' => 1, 'scope' => 1);
160 if(is_null($apiContext)) {
161 $apiContext = new PPApiContext();
164 if(!array_key_exists('grant_type', $params)) {
165 $params['grant_type'] = 'refresh_token';
167 if(!array_key_exists('refresh_token', $params)) {
168 $params['refresh_token'] = $this->getRefreshToken();
172 $call = new PPRestCall($apiContext);
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')