All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nimbusds.oauth2.sdk.ClientCredentialsGrant Maven / Gradle / Ivy

/*
 * oauth2-oidc-sdk
 *
 * Copyright 2012-2016, Connect2id Ltd and contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
 * this file except in compliance with the License. You may obtain a copy of the
 * License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

package com.nimbusds.oauth2.sdk;


import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.nimbusds.oauth2.sdk.util.MultivaluedMapUtils;
import net.jcip.annotations.Immutable;


/**
 * Client credentials grant. Used in access token requests where the client is
 * acting on its own behalf.
 *
 * 

Related specifications: * *

    *
  • OAuth 2.0 (RFC 6749), section 4.4.2. *
*/ @Immutable public class ClientCredentialsGrant extends AuthorizationGrant { /** * The grant type. */ public static final GrantType GRANT_TYPE = GrantType.CLIENT_CREDENTIALS; /** * Creates a new client credentials grant. The actual client * credentials are included in the * {@link com.nimbusds.oauth2.sdk.auth.ClientAuthentication client * authentication} of the {@link com.nimbusds.oauth2.sdk.TokenRequest}. */ public ClientCredentialsGrant() { super(GRANT_TYPE); } @Override public Map> toParameters() { Map> params = new LinkedHashMap<>(); params.put("grant_type", Collections.singletonList(GRANT_TYPE.getValue())); return params; } /** * Parses a client credentials grant from the specified request body * parameters. * *

Example: * *

	 * grant_type=client_credentials
	 * 
* * @param params The parameters. * * @return The client credentials grant. * * @throws ParseException If parsing failed. */ public static ClientCredentialsGrant parse(final Map> params) throws ParseException { // Parse grant type String grantTypeString = MultivaluedMapUtils.getFirstValue(params, "grant_type"); if (grantTypeString == null) { String msg = "Missing \"grant_type\" parameter"; throw new ParseException(msg, OAuth2Error.INVALID_REQUEST.appendDescription(": " + msg)); } if (! GrantType.parse(grantTypeString).equals(GRANT_TYPE)) { String msg = "The \"grant_type\" must be " + GRANT_TYPE; throw new ParseException(msg, OAuth2Error.UNSUPPORTED_GRANT_TYPE.appendDescription(": " + msg)); } return new ClientCredentialsGrant(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy