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.ClientInformationResponse;
025import com.nimbusds.oauth2.sdk.http.HTTPResponse;
026
027
028/**
029 * OpenID Connect client information response.
030 *
031 * <p>Example HTTP response:
032 *
033 * <pre>
034 * HTTP/1.1 200 OK
035 * Content-Type: application/json
036 * Cache-Control: no-store
037 * Pragma: no-cache
038 *
039 * {
040 *  "client_id"                       : "s6BhdRkqt3",
041 *  "client_secret"                   :"ZJYCqe3GGRvdrudKyZS0XhGv_Z45DuKhCUk0gBR1vZk",
042 *  "client_secret_expires_at"        : 1577858400,
043 *  "registration_access_token"       : "this.is.an.access.token.value.ffx83",
044 *  "registration_client_uri"         : "https://server.example.com/connect/register?client_id=s6BhdRkqt3",
045 *  "token_endpoint_auth_method"      : "client_secret_basic",
046 *  "application_type"                : "web",
047 *  "redirect_uris"                   : ["https://client.example.org/callback","https://client.example.org/callback2"],
048 *  "client_name"                     : "My Example",
049 *  "client_name#ja-Jpan-JP"          : "クライアント名",
050 *  "logo_uri"                        : "https://client.example.org/logo.png",
051 *  "subject_type"                    : "pairwise",
052 *  "sector_identifier_uri"           : "https://other.example.net/file_of_redirect_uris.json",
053 *  "jwks_uri"                        : "https://client.example.org/my_public_keys.jwks",
054 *  "userinfo_encrypted_response_alg" : "RSA1_5",
055 *  "userinfo_encrypted_response_enc" : "A128CBC-HS256",
056 *  "contacts"                        : ["[email protected]", "[email protected]"],
057 *  "request_uris"                    : ["https://client.example.org/rf.txt#qpXaRLh_n93TTR9F252ValdatUQvQiJi5BDub2BeznA"]
058 * }
059 * </pre>
060 *
061 * <p>Related specifications:
062 *
063 * <ul>
064 *     <li>OpenID Connect Dynamic Client Registration 1.0, section 3.2 and 4.3.
065 *     <li>OAuth 2.0 Dynamic Client Registration Management Protocol (RFC
066 *         7592), section 3.
067 *     <li>OAuth 2.0 Dynamic Client Registration Protocol (RFC 7591), section
068 *         3.2.1.
069 * </ul>
070 */
071@Immutable
072public class OIDCClientInformationResponse extends ClientInformationResponse {
073        
074        
075        /**
076         * Creates a new OpenID Connect client information response.
077         *
078         * @param clientInfo   The OpenID Connect client information. Must not
079         *                     be {@code null}.
080         * @param forNewClient {@code true} for a newly registered client,
081         *                     {@code false} for a retrieved or updated client.
082         */
083        public OIDCClientInformationResponse(final OIDCClientInformation clientInfo,
084                                             final boolean forNewClient) {
085
086                super(clientInfo, forNewClient);
087        }
088        
089        
090        /**
091         * Gets the OpenID Connect client information.
092         *
093         * @return The OpenID Connect client information.
094         */
095        public OIDCClientInformation getOIDCClientInformation() {
096
097                return (OIDCClientInformation)getClientInformation();
098        }
099        
100        
101        /**
102         * Parses an OpenID Connect client information response from the 
103         * specified HTTP response.
104         *
105         * @param httpResponse The HTTP response. Must not be {@code null}.
106         *
107         * @return The OpenID Connect client information response.
108         *
109         * @throws ParseException If the HTTP response couldn't be parsed to an
110         *                        OpenID Connect client information response.
111         */
112        public static OIDCClientInformationResponse parse(final HTTPResponse httpResponse)
113                throws ParseException {
114
115                httpResponse.ensureStatusCode(HTTPResponse.SC_OK, HTTPResponse.SC_CREATED);
116                OIDCClientInformation clientInfo = OIDCClientInformation.parse(httpResponse.getContentAsJSONObject());
117                boolean forNewClient = HTTPResponse.SC_CREATED == httpResponse.getStatusCode();
118                return new OIDCClientInformationResponse(clientInfo, forNewClient);
119        }
120}