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

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

package com.nimbusds.oauth2.sdk;


import java.util.Map;


/**
 * Authorisation grant. Extending classes should be immutable.
 *
 * 

Supported authorisation grant types: * *

    *
  • {@link GrantType#AUTHORIZATION_CODE Authorisation code} *
  • {@link GrantType#PASSWORD Resource owner password credentials} *
  • {@link GrantType#CLIENT_CREDENTIALS Client credentials} *
  • {@link GrantType#REFRESH_TOKEN Refresh token} *
  • {@link GrantType#JWT_BEARER} *
  • {@link GrantType#SAML2_BEARER} *
* *

Related specifications: * *

    *
  • OAuth 2.0 (RFC 6749), sections 1.3. *
*/ public abstract class AuthorizationGrant { /** * The authorisation grant type. */ private final GrantType type; /** * Creates a new authorisation grant. * * @param type The authorisation grant type. Must not be * {@code null}. */ protected AuthorizationGrant(final GrantType type) { if (type == null) throw new IllegalArgumentException("The grant type must not be null"); this.type = type; } /** * Gets the authorisation grant type. * * @return The authorisation grant type. */ public GrantType getType() { return type; } /** * Return the parameters for the authorisation grant. * * @return The parameters. */ public abstract Map toParameters(); /** * Parses an authorisation grant from the specified parameters. * * @param params The parameters. Must not be {@code null}. * * @return The authorisation grant. * * @throws ParseException If parsing failed or the grant type is not * supported. */ public static AuthorizationGrant parse(final Map params) throws ParseException { // Parse grant type String grantTypeString = params.get("grant_type"); if (grantTypeString == null) throw new ParseException("Missing \"grant_type\" parameter", OAuth2Error.INVALID_REQUEST); GrantType grantType = GrantType.parse(grantTypeString); if (grantType.equals(GrantType.AUTHORIZATION_CODE)) { return AuthorizationCodeGrant.parse(params); } else if (grantType.equals(GrantType.REFRESH_TOKEN)) { return RefreshTokenGrant.parse(params); } else if (grantType.equals(GrantType.PASSWORD)) { return ResourceOwnerPasswordCredentialsGrant.parse(params); } else if (grantType.equals(GrantType.CLIENT_CREDENTIALS)) { return ClientCredentialsGrant.parse(params); } else if (grantType.equals(GrantType.JWT_BEARER)) { return JWTBearerGrant.parse(params); } else if (grantType.equals(GrantType.SAML2_BEARER)) { return SAML2BearerGrant.parse(params); } else { throw new ParseException("Invalid or unsupported grant type: " + grantType, OAuth2Error.UNSUPPORTED_GRANT_TYPE); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy