001    package com.nimbusds.oauth2.sdk.auth;
002    
003    
004    import net.jcip.annotations.Immutable;
005    
006    import com.nimbusds.oauth2.sdk.id.Identifier;
007    
008    
009    /**
010     * Client authentication method at the Token endpoint. This class is immutable.
011     *
012     * <p>Constants are provided for four client authentication methods:
013     *
014     * <ul>
015     *     <li>{@link #CLIENT_SECRET_BASIC} (default)
016     *     <li>{@link #CLIENT_SECRET_POST}
017     *     <li>{@link #CLIENT_SECRET_JWT}
018     *     <li>{@link #PRIVATE_KEY_JWT}
019     * </ul>
020     *
021     * <p>Use the constructor to define a custom client authentication method.
022     *
023     * <p>Related specifications:
024     *
025     * <ul>
026     *     <li>OAuth 2.0 (RFC 6749), section 2.3.
027     * </ul>
028     *
029     * @author Vladimir Dzhuvinov
030     */
031    @Immutable
032    public final class ClientAuthenticationMethod extends Identifier {
033    
034    
035            /**
036             * Clients that have received a client secret from the authorisation 
037             * server authenticate with the authorisation server in accordance with
038             * section 3.2.1 of OAuth 2.0 using HTTP Basic authentication. This is 
039             * the default if no method has been registered for the client.
040             */
041            public static final ClientAuthenticationMethod CLIENT_SECRET_BASIC = 
042                    new ClientAuthenticationMethod("client_secret_basic");
043    
044    
045            /**
046             * Clients that have received a client secret from the authorisation 
047             * server authenticate with the authorisation server in accordance with
048             * section 3.2.1 of OAuth 2.0 by including the client credentials in 
049             * the request body.
050             */
051            public static final ClientAuthenticationMethod CLIENT_SECRET_POST =
052                    new ClientAuthenticationMethod("client_secret_post");
053    
054    
055            /**
056             * Clients that have received a client secret from the authorisation 
057             * server, create a JWT using an HMAC SHA algorithm, such as HMAC 
058             * SHA-256. The HMAC (Hash-based Message Authentication Code) is
059             * calculated using the value of client secret as the shared key. The 
060             * client authenticates in accordance with section 2.2 of (JWT) Bearer
061             * Token Profiles and OAuth 2.0 Assertion Profile. 
062             */
063            public static final ClientAuthenticationMethod CLIENT_SECRET_JWT =
064                    new ClientAuthenticationMethod("client_secret_jwt");
065    
066    
067            /**
068             * Clients that have registered a public key sign a JWT using the RSA 
069             * algorithm if a RSA key was registered or the ECDSA algorithm if an 
070             * Elliptic Curve key was registered (see JWA for the algorithm 
071             * identifiers). The client authenticates in accordance with section 
072             * 2.2 of (JWT) Bearer Token Profiles and OAuth 2.0 Assertion Profile.
073             */
074            public static final ClientAuthenticationMethod PRIVATE_KEY_JWT =
075                    new ClientAuthenticationMethod("private_key_jwt");
076    
077    
078            /**
079             * Gets the default client authentication method.
080             *
081             * @return {@link #CLIENT_SECRET_BASIC}
082             */
083            public static ClientAuthenticationMethod getDefault() {
084    
085                    return CLIENT_SECRET_BASIC;
086            }
087    
088    
089            /**
090             * Creates a new client authentication method with the specified value.
091             *
092             * @param value The authentication method value. Must not be 
093             *              {@code null} or empty string.
094             */
095            public ClientAuthenticationMethod(final String value) {
096    
097                    super(value);
098            }
099    
100    
101            @Override
102            public boolean equals(final Object object) {
103            
104                    return object != null && 
105                           object instanceof ClientAuthenticationMethod && 
106                           this.toString().equals(object.toString());
107            }
108    }