001package com.nimbusds.openid.connect.sdk.rp;
002
003
004import net.jcip.annotations.Immutable;
005
006import com.nimbusds.oauth2.sdk.ParseException;
007import com.nimbusds.oauth2.sdk.client.ClientRegistrationErrorResponse;
008import com.nimbusds.oauth2.sdk.client.ClientRegistrationResponse;
009import com.nimbusds.oauth2.sdk.http.HTTPResponse;
010
011
012/**
013 * Parser of OpenID Connect client registration response messages.
014 *
015 * <p>Related specifications:
016 *
017 * <ul>
018 *     <li>OpenID Connect Dynamic Client Registration 1.0, section 3.2 and 3.3.
019 *     <li>OAuth 2.0 Dynamic Client Registration Protocol 
020 *         (draft-ietf-oauth-dyn-reg-14), section 3.2, 4.3 and 5.
021 * </ul>
022 *
023 * @author Vladimir Dzhuvinov
024 */
025@Immutable
026public class OIDCClientRegistrationResponseParser {
027        
028        
029        /**
030         * Parses an OpenID Connect client registration response from the 
031         * specified HTTP response.
032         *
033         * @param httpResponse The HTTP response. Must not be {@code null}.
034         *
035         * @return The OpenID Connect client registration response.
036         *
037         * @throws ParseException If the HTTP response couldn't be parsed to an
038         *                        OpenID Connect client registration response.
039         */
040        public static ClientRegistrationResponse parse(final HTTPResponse httpResponse)
041                throws ParseException {
042                
043                if (httpResponse.getStatusCode() == HTTPResponse.SC_OK)
044                        return OIDCClientInformationResponse.parse(httpResponse);
045                else
046                        return ClientRegistrationErrorResponse.parse(httpResponse);
047        }
048        
049        
050        /**
051         * Prevents public instantiation.
052         */
053        private OIDCClientRegistrationResponseParser() { }
054}