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.openid.connect.sdk.rp; 019 020 021import net.jcip.annotations.Immutable; 022 023import com.nimbusds.oauth2.sdk.ParseException; 024import com.nimbusds.oauth2.sdk.client.ClientRegistrationErrorResponse; 025import com.nimbusds.oauth2.sdk.client.ClientRegistrationResponse; 026import com.nimbusds.oauth2.sdk.http.HTTPResponse; 027 028 029/** 030 * Parser of OpenID Connect client registration response messages. 031 * 032 * <p>Related specifications: 033 * 034 * <ul> 035 * <li>OpenID Connect Dynamic Client Registration 1.0 036 * <li>OAuth 2.0 Dynamic Client Registration Protocol (RFC 7591) 037 * </ul> 038 */ 039@Immutable 040public class OIDCClientRegistrationResponseParser { 041 042 043 /** 044 * Parses an OpenID Connect client registration response from the 045 * specified HTTP response. 046 * 047 * @param httpResponse The HTTP response. Must not be {@code null}. 048 * 049 * @return The OpenID Connect client registration response. 050 * 051 * @throws ParseException If the HTTP response couldn't be parsed to an 052 * OpenID Connect client registration response. 053 */ 054 public static ClientRegistrationResponse parse(final HTTPResponse httpResponse) 055 throws ParseException { 056 057 final int statusCode = httpResponse.getStatusCode(); 058 059 if (statusCode == HTTPResponse.SC_OK || statusCode == HTTPResponse.SC_CREATED) { 060 return OIDCClientInformationResponse.parse(httpResponse); 061 } else { 062 return ClientRegistrationErrorResponse.parse(httpResponse); 063 } 064 } 065 066 067 /** 068 * Prevents public instantiation. 069 */ 070 private OIDCClientRegistrationResponseParser() { } 071}