Get the grant by its name

@throws OAuth2Exception (unsupported_grant_type) When grant type is not registered
431181
public function getGrant(string $grantType): GrantInterface
    {
        if ($this->hasGrant($grantType)) {
            return $this->grants[$grantType];
        }

        // If we reach here... then no grant was found. Not good!
        throw OAuth2Exception::unsupportedGrantType(sprintf(
            'Grant type "%s" is not supported by this server',
            $grantType
        ));
    }
863055
@Override
    public String getAuthType() {
        String type = null;
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "getAuthType: " + type);
        }
        return type;
    }
987907
private function fetchAccessToken() {
        // Setup the params
        $params = [
            'client_id'     => $this->clientID,
            'client_secret' => $this->secret,
            'grant_type'    => 'authorization_code',
            'code'          => $this->requestToken
        ];

        if (isset($this->redirectURI)) {
            $params['redirect_uri'] = $this->redirectURI;
        }

        // Parse the cURL result
        $this->parseAccessToken(CURL::post($this->url, $params));
    }
405360
def get_handler(self, grant_type):
        
        if grant_type == 'authorization_code':
            return self.authorization_code
        elif grant_type == 'refresh_token':
            return self.refresh_token
        elif grant_type == 'password':
            return self.password
        return None
1075467
public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseInterface $response)
    {
        foreach ($this->enabledGrantTypes as $grantType) {
            if (!$grantType->canRespondToAccessTokenRequest($request)) {
                continue;
            }
            $tokenResponse = $grantType->respondToAccessTokenRequest(
                $request,
                $this->getResponseType(),
                $this->grantTypeAccessTokenTTL[$grantType->getIdentifier()]
            );

            if ($tokenResponse instanceof ResponseTypeInterface) {
                return $tokenResponse->generateHttpResponse($response);
            }
        }

        throw OAuthServerException::unsupportedGrantType();
    }
1127570
private ModelAndView getImplicitGrantResponse(AuthorizationRequest authorizationRequest) {
		try {
			TokenRequest tokenRequest = getOAuth2RequestFactory().createTokenRequest(authorizationRequest, "implicit");
			OAuth2Request storedOAuth2Request = getOAuth2RequestFactory().createOAuth2Request(authorizationRequest);
			OAuth2AccessToken accessToken = getAccessTokenForImplicitGrant(tokenRequest, storedOAuth2Request);
			if (accessToken == null) {
				throw new UnsupportedResponseTypeException("Unsupported response type: token");
			}
			return new ModelAndView(new RedirectView(appendAccessToken(authorizationRequest, accessToken), false, true,
					false));
		}
		catch (OAuth2Exception e) {
			return new ModelAndView(new RedirectView(getUnsuccessfulRedirect(authorizationRequest, e, true), false,
					true, false));
		}
	}
911721
function get($field_name, $default=null)
    {
        if (!Auth_OpenID_checkFieldName($field_name)) {
            return null;
        }

        return Auth_OpenID::arrayGet($this->data, $field_name, $default);
    }
943133
def get_token(code, token_service, client_id, client_secret, redirect_uri,
              grant_type):
  """"""
  data = {
      'code': code,
      'client_id': client_id,
      'client_secret': client_secret,
      'redirect_uri': redirect_uri,
      'grant_type': grant_type,
  }
  # Get the default http client
  resp = requests.post(token_service, data, verify=False)
  return resp.json()
796353
private ModelAndView getImplicitGrantOrHybridResponse(
      AuthorizationRequest authorizationRequest,
      Authentication authentication,
      String grantType
    ) {
        OAuth2AccessToken accessToken;
        try {
            TokenRequest tokenRequest = getOAuth2RequestFactory().createTokenRequest(authorizationRequest, GRANT_TYPE_IMPLICIT);
            Map<String, String> requestParameters = new HashMap<>(authorizationRequest.getRequestParameters());
            requestParameters.put(GRANT_TYPE, grantType);
            authorizationRequest.setRequestParameters(requestParameters);
            OAuth2Request storedOAuth2Request = getOAuth2RequestFactory().createOAuth2Request(authorizationRequest);
            accessToken = getAccessTokenForImplicitGrantOrHybrid(tokenRequest, storedOAuth2Request, grantType);
            if (accessToken == null) {
                throw new UnsupportedResponseTypeException("Unsupported response type: token or id_token");
            }
            return new ModelAndView(
              new RedirectView(
                buildRedirectURI(authorizationRequest, accessToken, authentication),
                false,
                true,
                false
              )
            );
        } catch (OAuth2Exception e) {
            return new ModelAndView(new RedirectView(getUnsuccessfulRedirect(authorizationRequest, e, true), false,
              true, false));
        }
    }
60597
def get_token(self, client_id, target, api_type, grant_type,
                  id_token=None, refresh_token=None, scope='openid'):

        

        if id_token and refresh_token:
            raise ValueError('Only one of id_token or refresh_token '
                             'can be None')

        data = {
            'client_id': client_id,
            'grant_type': grant_type,
            'target': target,
            'scope': scope,
            'api_type': api_type,
        }

        if id_token:
            data.update({'id_token': id_token})
        elif refresh_token:
            data.update({'refresh_token': refresh_token})
        else:
            raise ValueError('Either id_token or refresh_token must '
                             'have a value')

        return self.post(
            'https://{}/delegation'.format(self.domain),
            headers={'Content-Type': 'application/json'},
            data=data
        )
442451
public static String getAccessToken() throws MPException {
        if (StringUtils.isEmpty(MercadoPago.SDK.getClientId()) ||
                StringUtils.isEmpty(MercadoPago.SDK.getClientSecret())) {
            throw new MPException("\"client_id\" and \"client_secret\" can not be \"null\" when getting the \"access_token\"");
        }

        JsonObject jsonPayload = new JsonObject();
        jsonPayload.addProperty("grant_type", "client_credentials");
        jsonPayload.addProperty("client_id", MercadoPago.SDK.getClientId());
        jsonPayload.addProperty("client_secret", MercadoPago.SDK.getClientSecret());

        String access_token = null;
        String baseUri = MercadoPago.SDK.getBaseUrl();
        MPApiResponse response = new MPRestClient().executeRequest(
                HttpMethod.POST,
                baseUri + "/oauth/token",
                PayloadType.JSON,
                jsonPayload,
                null);


        if (response.getStatusCode() == 200) {
            JsonElement jsonElement = response.getJsonElementResponse();
            if (jsonElement.isJsonObject()) {
                access_token = ((JsonObject)jsonElement).get("access_token").getAsString();
            }
        } else {
            throw new MPException("Can not retrieve the \"access_token\"");
        }
        return access_token;
    }
626265
public function getAccessToken($grant = 'client_credentials', array $options = [])
    {
        if($this->accessToken !== null) {
            return $this->accessToken;
        }

        return $this->accessToken = $this->issueAccessToken($grant, $options);
    }
979207
public static authorizationaction get(nitro_service service, String name) throws Exception{
		authorizationaction obj = new authorizationaction();
		obj.set_name(name);
		authorizationaction response = (authorizationaction) obj.get_resource(service);
		return response;
	}
82422
private String getImplicitGrantResponse(AuthorizationRequest authorizationRequest) {
        try {
            TokenRequest tokenRequest = requestFactory.createTokenRequest(authorizationRequest, "implicit");
            OAuth2Request storedOAuth2Request = requestFactory.createOAuth2Request(authorizationRequest);
            OAuth2AccessToken accessToken = getAccessTokenForImplicitGrant(tokenRequest, storedOAuth2Request);
            if (isNull(accessToken)) {
                throw new UnsupportedResponseTypeException("Unsupported response type: token");
            }
            return appendAccessToken(authorizationRequest, accessToken);
        } catch (OAuth2Exception e) {
            return getUnsuccessfulRedirect(authorizationRequest, e, true);
        }
    }
638748
protected function oAuthPostRequest($grant_type, $client_id, $client_secret)
    {
        // verify the required parameter 'grant_type' is set
        if ($grant_type === null) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $grant_type when calling oAuthPost'
            );
        }
        // verify the required parameter 'client_id' is set
        if ($client_id === null) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $client_id when calling oAuthPost'
            );
        }
        // verify the required parameter 'client_secret' is set
        if ($client_secret === null) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $client_secret when calling oAuthPost'
            );
        }

        $resourcePath = '/oauth2/token';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // form params
        if ($grant_type !== null) {
            $formParams['grant_type'] = ObjectSerializer::toFormValue($grant_type);
        }
        // form params
        if ($client_id !== null) {
            $formParams['client_id'] = ObjectSerializer::toFormValue($client_id);
        }
        // form params
        if ($client_secret !== null) {
            $formParams['client_secret'] = ObjectSerializer::toFormValue($client_secret);
        }
        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/x-www-form-urlencoded']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
            else if (gettype($httpBody) == 'array' && $headers['Content-Type'] === 'application/json') {
                $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }
        if($this->config->getAccessToken()!==''){
            $defaultHeaders['Authorization']= 'Bearer ' . $this->config->getAccessToken();
        }
        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }
530213
public function getAccessToken($code, $grant = 'authorization_code')
    {
        $this->validateCsrf();
        return $this->provider->getAccessToken($grant, ['code' => $code]);
    }
745785
public String getNewToken(GrantType grantType) throws FoxHttpException, MalformedURLException {
        FoxHttpRequest request = this.generateRequestForGrantType(grantType);
        this.getOAuth2RequestExecutor().executeOAuth2Request(request, this);
        return getOAuth2Store().getAccessToken();
    }