当前位置: 首页>>代码示例>>PHP>>正文


PHP RequestInterface::query方法代码示例

本文整理汇总了PHP中OAuth2\RequestInterface::query方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::query方法的具体用法?PHP RequestInterface::query怎么用?PHP RequestInterface::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OAuth2\RequestInterface的用法示例。


在下文中一共展示了RequestInterface::query方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getAccessTokenParameter

 /**
  * This is a convenience function that can be used to get the token, which can then
  * be passed to getAccessTokenData(). The constraints specified by the draft are
  * attempted to be adheared to in this method.
  *
  * As per the Bearer spec (draft 8, section 2) - there are three ways for a client
  * to specify the bearer token, in order of preference: Authorization Header,
  * POST and GET.
  *
  * NB: Resource servers MUST accept tokens via the Authorization scheme
  * (http://tools.ietf.org/html/rfc6750#section-2).
  *
  * @todo Should we enforce TLS/SSL in this function?
  *
  * @see http://tools.ietf.org/html/rfc6750#section-2.1
  * @see http://tools.ietf.org/html/rfc6750#section-2.2
  * @see http://tools.ietf.org/html/rfc6750#section-2.3
  *
  * Old Android version bug (at least with version 2.2)
  * @see http://code.google.com/p/android/issues/detail?id=6684
  *
  */
 public function getAccessTokenParameter(RequestInterface $request, ResponseInterface $response)
 {
     $headers = $request->headers('AUTHORIZATION');
     //        echo ($headers."bearer");
     /**
      * Ensure more than one method is not used for including an
      * access token
      *
      * @see http://tools.ietf.org/html/rfc6750#section-3.1
      */
     $methodsUsed = !empty($headers) + (bool) $request->query($this->config['token_param_name']) + (bool) $request->request($this->config['token_param_name']);
     //        echo ($methodsUsed);
     //        echo ("<br>".$this->config['token_param_name']."<br>");
     if ($methodsUsed > 1) {
         $response->setError(400, 'invalid_request', 'Only one method may be used to authenticate at a time (Auth header, GET or POST)');
         return null;
     }
     /**
      * If no authentication is provided, set the status code
      * to 401 and return no other error information
      *
      * @see http://tools.ietf.org/html/rfc6750#section-3.1
      */
     if ($methodsUsed == 0) {
         $response->setStatusCode(401);
         //            echo ("no auth");
         return null;
     }
     // HEADER: Get the access token from the header
     if (!empty($headers)) {
         if (!preg_match('/' . $this->config['token_bearer_header_name'] . '\\s(\\S+)/i', $headers, $matches)) {
             $response->setError(400, 'invalid_request', 'Malformed auth header');
             return null;
         }
         return $matches[1];
     }
     if ($request->request($this->config['token_param_name'])) {
         // // POST: Get the token from POST data
         if (!in_array(strtolower($request->server('REQUEST_METHOD')), array('post', 'put'))) {
             $response->setError(400, 'invalid_request', 'When putting the token in the body, the method must be POST or PUT', '#section-2.2');
             return null;
         }
         $contentType = $request->server('CONTENT_TYPE');
         if (false !== ($pos = strpos($contentType, ';'))) {
             $contentType = substr($contentType, 0, $pos);
         }
         if ($contentType !== null && $contentType != 'application/x-www-form-urlencoded') {
             // IETF specifies content-type. NB: Not all webservers populate this _SERVER variable
             // @see http://tools.ietf.org/html/rfc6750#section-2.2
             $response->setError(400, 'invalid_request', 'The content type for POST requests must be "application/x-www-form-urlencoded"');
             return null;
         }
         return $request->request($this->config['token_param_name']);
     }
     // GET method
     return $request->query($this->config['token_param_name']);
 }
开发者ID:Insantani,项目名称:SourceTree-diovi,代码行数:79,代码来源:Bearer.php

示例2: getAccessTokenParameter

 /**
  * This is a convenience function that can be used to get the token, which can then
  * be passed to getAccessTokenData(). The constraints specified by the draft are
  * attempted to be adheared to in this method.
  *
  * As per the Bearer spec (draft 8, section 2) - there are three ways for a client
  * to specify the bearer token, in order of preference: Authorization Header,
  * POST and GET.
  *
  * NB: Resource servers MUST accept tokens via the Authorization scheme
  * (http://tools.ietf.org/html/rfc6750#section-2).
  *
  * @todo Should we enforce TLS/SSL in this function?
  *
  * @see http://tools.ietf.org/html/rfc6750#section-2.1
  * @see http://tools.ietf.org/html/rfc6750#section-2.2
  * @see http://tools.ietf.org/html/rfc6750#section-2.3
  *
  * Old Android version bug (at least with version 2.2)
  * @see http://code.google.com/p/android/issues/detail?id=6684
  *
  */
 public function getAccessTokenParameter(RequestInterface $request, ResponseInterface $response)
 {
     $headers = $request->headers('AUTHORIZATION');
     // Check that exactly one method was used
     $methodsUsed = !empty($headers) + !is_null($request->query($this->config['token_param_name'])) + !is_null($request->request($this->config['token_param_name']));
     if ($methodsUsed > 1) {
         $response->setError(400, 'invalid_request', 'Only one method may be used to authenticate at a time (Auth header, GET or POST)');
         return null;
     }
     if ($methodsUsed == 0) {
         $response->setStatusCode(401);
         return null;
     }
     // HEADER: Get the access token from the header
     if (!empty($headers)) {
         if (!preg_match('/' . $this->config['token_bearer_header_name'] . '\\s(\\S+)/', $headers, $matches)) {
             $response->setError(400, 'invalid_request', 'Malformed auth header');
             return null;
         }
         return $matches[1];
     }
     if ($request->request($this->config['token_param_name'])) {
         // POST: Get the token from POST data
         if (strtolower($request->server('REQUEST_METHOD')) != 'post') {
             $response->setError(400, 'invalid_request', 'When putting the token in the body, the method must be POST');
             return null;
         }
         $contentType = $request->server('CONTENT_TYPE');
         if (false !== ($pos = strpos($contentType, ';'))) {
             $contentType = substr($contentType, 0, $pos);
         }
         if ($contentType !== null && $contentType != 'application/x-www-form-urlencoded') {
             // IETF specifies content-type. NB: Not all webservers populate this _SERVER variable
             // @see http://tools.ietf.org/html/rfc6750#section-2.2
             $response->setError(400, 'invalid_request', 'The content type for POST requests must be "application/x-www-form-urlencoded"');
             return null;
         }
         return $request->request($this->config['token_param_name']);
     }
     // GET method
     return $request->query($this->config['token_param_name']);
 }
开发者ID:emildev35,项目名称:processmaker,代码行数:64,代码来源:Bearer.php

示例3: getAccessTokenParameter

 public function getAccessTokenParameter(RequestInterface $request, ResponseInterface $response)
 {
     $headers = $request->headers('AUTHORIZATION');
     $methodsUsed = !empty($headers) + (bool) $request->query($this->config['token_param_name']) + (bool) $request->request($this->config['token_param_name']);
     if ($methodsUsed > 1) {
         $response->setError(400, 'invalid_request', 'Only one method may be used to authenticate at a time (Auth header, GET or POST)');
         return null;
     }
     if ($methodsUsed == 0) {
         $response->setStatusCode(401);
         return null;
     }
     // HEADER: Get the access token from the header
     if (!empty($headers)) {
         if (!preg_match('/' . $this->config['token_bearer_header_name'] . '\\s(\\S+)/i', $headers, $matches)) {
             $response->setError(400, 'invalid_request', 'Malformed auth header');
             return null;
         }
         return $matches[1];
     }
     if ($request->request($this->config['token_param_name'])) {
         // // POST: Get the token from POST data
         if (!in_array(strtolower($request->server('REQUEST_METHOD')), array('post', 'put'))) {
             $response->setError(400, 'invalid_request', 'When putting the token in the body, the method must be POST or PUT', '#section-2.2');
             return null;
         }
         $contentType = $request->server('CONTENT_TYPE');
         if (false !== ($pos = strpos($contentType, ';'))) {
             $contentType = substr($contentType, 0, $pos);
         }
         if ($contentType !== null && $contentType != 'application/x-www-form-urlencoded') {
             $response->setError(400, 'invalid_request', 'The content type for POST requests must be "application/x-www-form-urlencoded"');
             return null;
         }
         return $request->request($this->config['token_param_name']);
     }
     return $request->query($this->config['token_param_name']);
 }
开发者ID:HarkiratGhotra,项目名称:application,代码行数:38,代码来源:Bearer.php

示例4: setNotAuthorizedResponse

 protected function setNotAuthorizedResponse(RequestInterface $request, ResponseInterface $response, $redirect_uri, $user_id = null)
 {
     $prompt = $request->query('prompt', 'consent');
     if ($prompt == 'none') {
         if (is_null($user_id)) {
             $error = 'login_required';
             $error_message = 'The user must log in';
         } else {
             $error = 'interaction_required';
             $error_message = 'The user must grant access to your application';
         }
     } else {
         $error = 'consent_required';
         $error_message = 'The user denied access to your application';
     }
     $response->setRedirect($this->config['redirect_status_code'], $redirect_uri, $this->getState(), $error, $error_message);
 }
开发者ID:hoaquynhtim99,项目名称:nukeviet-oauth2,代码行数:17,代码来源:AuthorizeController.php

示例5: validateAuthorizeRequest

 public function validateAuthorizeRequest(RequestInterface $request, ResponseInterface $response)
 {
     // Make sure a valid client id was supplied (we can not redirect because we were unable to verify the URI)
     if (!($client_id = $request->query('client_id', $request->request('client_id')))) {
         // We don't have a good URI to use
         $response->setError(400, 'invalid_client', "No client id supplied");
         return false;
     }
     // Get client details
     if (!($clientData = $this->clientStorage->getClientDetails($client_id))) {
         $response->setError(400, 'invalid_client', 'The client id supplied is invalid');
         return false;
     }
     $registered_redirect_uri = isset($clientData['redirect_uri']) ? $clientData['redirect_uri'] : '';
     // Make sure a valid redirect_uri was supplied. If specified, it must match the clientData URI.
     // @see http://tools.ietf.org/html/rfc6749#section-3.1.2
     // @see http://tools.ietf.org/html/rfc6749#section-4.1.2.1
     // @see http://tools.ietf.org/html/rfc6749#section-4.2.2.1
     if ($supplied_redirect_uri = $request->query('redirect_uri', $request->request('redirect_uri'))) {
         // validate there is no fragment supplied
         $parts = parse_url($supplied_redirect_uri);
         if (isset($parts['fragment']) && $parts['fragment']) {
             $response->setError(400, 'invalid_uri', 'The redirect URI must not contain a fragment');
             return false;
         }
         // validate against the registered redirect uri(s) if available
         if ($registered_redirect_uri && !$this->validateRedirectUri($supplied_redirect_uri, $registered_redirect_uri)) {
             $response->setError(400, 'redirect_uri_mismatch', 'The redirect URI provided is missing or does not match', '#section-3.1.2');
             return false;
         }
         $redirect_uri = $supplied_redirect_uri;
     } else {
         // use the registered redirect_uri if none has been supplied, if possible
         if (!$registered_redirect_uri) {
             $response->setError(400, 'invalid_uri', 'No redirect URI was supplied or stored');
             return false;
         }
         if (count(explode(' ', $registered_redirect_uri)) > 1) {
             $response->setError(400, 'invalid_uri', 'A redirect URI must be supplied when multiple redirect URIs are registered', '#section-3.1.2.3');
             return false;
         }
         $redirect_uri = $registered_redirect_uri;
     }
     // Select the redirect URI
     $response_type = $request->query('response_type', $request->request('response_type'));
     // for multiple-valued response types - make them alphabetical
     if (false !== strpos($response_type, ' ')) {
         $types = explode(' ', $response_type);
         sort($types);
         $response_type = ltrim(implode(' ', $types));
     }
     $state = $request->query('state', $request->request('state'));
     // type and client_id are required
     if (!$response_type || !in_array($response_type, $this->getValidResponseTypes())) {
         $response->setRedirect($this->config['redirect_status_code'], $redirect_uri, $state, 'invalid_request', 'Invalid or missing response type', null);
         return false;
     }
     if ($response_type == self::RESPONSE_TYPE_AUTHORIZATION_CODE) {
         if (!isset($this->responseTypes['code'])) {
             $response->setRedirect($this->config['redirect_status_code'], $redirect_uri, $state, 'unsupported_response_type', 'authorization code grant type not supported', null);
             return false;
         }
         if (!$this->clientStorage->checkRestrictedGrantType($client_id, 'authorization_code')) {
             $response->setRedirect($this->config['redirect_status_code'], $redirect_uri, $state, 'unauthorized_client', 'The grant type is unauthorized for this client_id', null);
             return false;
         }
         if ($this->responseTypes['code']->enforceRedirect() && !$redirect_uri) {
             $response->setError(400, 'redirect_uri_mismatch', 'The redirect URI is mandatory and was not supplied');
             return false;
         }
     } else {
         if (!$this->config['allow_implicit']) {
             $response->setRedirect($this->config['redirect_status_code'], $redirect_uri, $state, 'unsupported_response_type', 'implicit grant type not supported', null);
             return false;
         }
         if (!$this->clientStorage->checkRestrictedGrantType($client_id, 'implicit')) {
             $response->setRedirect($this->config['redirect_status_code'], $redirect_uri, $state, 'unauthorized_client', 'The grant type is unauthorized for this client_id', null);
             return false;
         }
     }
     // validate requested scope if it exists
     $requestedScope = $this->scopeUtil->getScopeFromRequest($request);
     if ($requestedScope) {
         // restrict scope by client specific scope if applicable,
         // otherwise verify the scope exists
         $clientScope = $this->clientStorage->getClientScope($client_id);
         if (is_null($clientScope) && !$this->scopeUtil->scopeExists($requestedScope) || $clientScope && !$this->scopeUtil->checkScope($requestedScope, $clientScope)) {
             $response->setRedirect($this->config['redirect_status_code'], $redirect_uri, $state, 'invalid_scope', 'An unsupported scope was requested', null);
             return false;
         }
     } else {
         // use a globally-defined default scope
         $defaultScope = $this->scopeUtil->getDefaultScope($client_id);
         if (false === $defaultScope) {
             $response->setRedirect($this->config['redirect_status_code'], $redirect_uri, $state, 'invalid_client', 'This application requires you specify a scope parameter', null);
             return false;
         }
         $requestedScope = $defaultScope;
     }
     // Validate state parameter exists (if configured to enforce this)
//.........这里部分代码省略.........
开发者ID:thangredweb,项目名称:redCORE,代码行数:101,代码来源:AuthorizeController.php

示例6: getScopeFromRequest

 public function getScopeFromRequest(RequestInterface $request)
 {
     // "scope" is valid if passed in either POST or QUERY
     return $request->request('scope', $request->query('scope'));
 }
开发者ID:hoaquynhtim99,项目名称:nukeviet-oauth2,代码行数:5,代码来源:Scope.php

示例7: validateAuthorizeRequest

 public function validateAuthorizeRequest(RequestInterface $request, ResponseInterface $response)
 {
     // Make sure a valid client id was supplied (we can not redirect because we were unable to verify the URI)
     if (!($client_id = $request->query("client_id"))) {
         // We don't have a good URI to use
         $response->setError(400, 'invalid_client', "No client id supplied");
         return false;
     }
     // Get client details
     if (!($clientData = $this->clientStorage->getClientDetails($client_id))) {
         $response->setError(400, 'invalid_client', 'The client id supplied is invalid');
         return false;
     }
     $registered_redirect_uri = isset($clientData['redirect_uri']) ? $clientData['redirect_uri'] : '';
     // Make sure a valid redirect_uri was supplied. If specified, it must match the clientData URI.
     // @see http://tools.ietf.org/html/rfc6749#section-3.1.2
     // @see http://tools.ietf.org/html/rfc6749#section-4.1.2.1
     // @see http://tools.ietf.org/html/rfc6749#section-4.2.2.1
     if ($redirect_uri = $request->query('redirect_uri')) {
         // validate there is no fragment supplied
         $parts = parse_url($redirect_uri);
         if (isset($parts['fragment']) && $parts['fragment']) {
             $response->setError(400, 'invalid_uri', 'The redirect URI must not contain a fragment');
             return false;
         }
         // validate against the registered redirect uri(s) if available
         if ($registered_redirect_uri && !$this->validateRedirectUri($redirect_uri, $registered_redirect_uri)) {
             $response->setError(400, 'redirect_uri_mismatch', 'The redirect URI provided is missing or does not match', '#section-3.1.2');
             return false;
         }
     } else {
         // use the registered redirect_uri if none has been supplied, if possible
         if (!$registered_redirect_uri) {
             $response->setError(400, 'invalid_uri', 'No redirect URI was supplied or stored');
             return false;
         }
         if (count(explode(' ', $registered_redirect_uri)) > 1) {
             $response->setError(400, 'invalid_uri', 'A redirect URI must be supplied when multiple redirect URIs are registered', '#section-3.1.2.3');
             return false;
         }
         $redirect_uri = $registered_redirect_uri;
     }
     // Select the redirect URI
     $response_type = $request->query('response_type');
     $state = $request->query('state');
     if (!($scope = $this->scopeUtil->getScopeFromRequest($request))) {
         $scope = $this->scopeUtil->getDefaultScope();
     }
     // type and client_id are required
     if (!$response_type || !in_array($response_type, array(self::RESPONSE_TYPE_AUTHORIZATION_CODE, self::RESPONSE_TYPE_ACCESS_TOKEN))) {
         $response->setRedirect(302, $redirect_uri, $state, 'invalid_request', 'Invalid or missing response type', null);
         return false;
     }
     if ($response_type == self::RESPONSE_TYPE_AUTHORIZATION_CODE) {
         if (!isset($this->responseTypes['code'])) {
             $response->setRedirect(302, $redirect_uri, $state, 'unsupported_response_type', 'authorization code grant type not supported', null);
             return false;
         }
         if (!$this->clientStorage->checkRestrictedGrantType($client_id, 'authorization_code')) {
             $response->setRedirect(302, $redirect_uri, $state, 'unauthorized_client', 'The grant type is unauthorized for this client_id', null);
             return false;
         }
         if ($this->responseTypes['code']->enforceRedirect() && !$redirect_uri) {
             $response->setError(400, 'redirect_uri_mismatch', 'The redirect URI is mandatory and was not supplied');
             return false;
         }
     }
     if ($response_type == self::RESPONSE_TYPE_ACCESS_TOKEN) {
         if (!$this->config['allow_implicit']) {
             $response->setRedirect(302, $redirect_uri, $state, 'unsupported_response_type', 'implicit grant type not supported', null);
             return false;
         }
         if (!$this->clientStorage->checkRestrictedGrantType($client_id, 'implicit')) {
             $response->setRedirect(302, $redirect_uri, $state, 'unauthorized_client', 'The grant type is unauthorized for this client_id', null);
             return false;
         }
     }
     // Validate that the requested scope is supported
     if (false === $scope) {
         $response->setRedirect(302, $redirect_uri, $state, 'invalid_client', 'This application requires you specify a scope parameter', null);
         return false;
     }
     if (!is_null($scope) && !$this->scopeUtil->scopeExists($scope, $client_id)) {
         $response->setRedirect(302, $redirect_uri, $state, 'invalid_scope', 'An unsupported scope was requested', null);
         return false;
     }
     // Validate state parameter exists (if configured to enforce this)
     if ($this->config['enforce_state'] && !$state) {
         $response->setRedirect(302, $redirect_uri, null, 'invalid_request', 'The state parameter is required');
         return false;
     }
     // Return retrieved client details together with input
     return array_merge(array('scope' => $scope, 'state' => $state), $clientData, $request->getAllQueryParameters(), array('redirect_uri' => $redirect_uri));
 }
开发者ID:sarfraznawaz2005,项目名称:sso-examples,代码行数:94,代码来源:AuthorizeController.php


注:本文中的OAuth2\RequestInterface::query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。