001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.oauth2.sdk; 019 020 021import java.util.Collections; 022import java.util.LinkedHashMap; 023import java.util.List; 024import java.util.Map; 025 026import net.jcip.annotations.Immutable; 027 028 029/** 030 * Client credentials grant. Used in access token requests where the client is 031 * acting on its own behalf. 032 * 033 * <p>Related specifications: 034 * 035 * <ul> 036 * <li>OAuth 2.0 (RFC 6749) 037 * </ul> 038 */ 039@Immutable 040public class ClientCredentialsGrant extends AuthorizationGrant { 041 042 043 /** 044 * The grant type. 045 */ 046 public static final GrantType GRANT_TYPE = GrantType.CLIENT_CREDENTIALS; 047 048 049 /** 050 * Creates a new client credentials grant. The actual client 051 * credentials are included in the 052 * {@link com.nimbusds.oauth2.sdk.auth.ClientAuthentication client 053 * authentication} of the {@link com.nimbusds.oauth2.sdk.TokenRequest}. 054 */ 055 public ClientCredentialsGrant() { 056 057 super(GRANT_TYPE); 058 } 059 060 061 @Override 062 public Map<String,List<String>> toParameters() { 063 064 Map<String,List<String>> params = new LinkedHashMap<>(); 065 params.put("grant_type", Collections.singletonList(GRANT_TYPE.getValue())); 066 return params; 067 } 068 069 070 /** 071 * Parses a client credentials grant from the specified request body 072 * parameters. 073 * 074 * <p>Example: 075 * 076 * <pre> 077 * grant_type=client_credentials 078 * </pre> 079 * 080 * @param params The parameters. 081 * 082 * @return The client credentials grant. 083 * 084 * @throws ParseException If parsing failed. 085 */ 086 public static ClientCredentialsGrant parse(final Map<String,List<String>> params) 087 throws ParseException { 088 089 GrantType.ensure(GRANT_TYPE, params); 090 091 return new ClientCredentialsGrant(); 092 } 093}