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 (RFC 7591), sections 020 * 2 and 3.2. 021 * </ul> 022 */ 023@Immutable 024public class OIDCClientRegistrationResponseParser { 025 026 027 /** 028 * Parses an OpenID Connect client registration response from the 029 * specified HTTP response. 030 * 031 * @param httpResponse The HTTP response. Must not be {@code null}. 032 * 033 * @return The OpenID Connect client registration response. 034 * 035 * @throws ParseException If the HTTP response couldn't be parsed to an 036 * OpenID Connect client registration response. 037 */ 038 public static ClientRegistrationResponse parse(final HTTPResponse httpResponse) 039 throws ParseException { 040 041 final int statusCode = httpResponse.getStatusCode(); 042 043 if (statusCode == HTTPResponse.SC_OK || statusCode == HTTPResponse.SC_CREATED) { 044 return OIDCClientInformationResponse.parse(httpResponse); 045 } else { 046 return ClientRegistrationErrorResponse.parse(httpResponse); 047 } 048 } 049 050 051 /** 052 * Prevents public instantiation. 053 */ 054 private OIDCClientRegistrationResponseParser() { } 055}