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"                        : ["ve7jtb@example.org", "mary@example.org"],
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
065 *     <li>OAuth 2.0 Dynamic Client Registration Management Protocol (RFC 7592)
066 *     <li>OAuth 2.0 Dynamic Client Registration Protocol (RFC 7591)
067 * </ul>
068 */
069@Immutable
070public class OIDCClientInformationResponse extends ClientInformationResponse {
071        
072        
073        /**
074         * Creates a new OpenID Connect client information response.
075         *
076         * @param clientInfo   The OpenID Connect client information. Must not
077         *                     be {@code null}.
078         * @param forNewClient {@code true} for a newly registered client,
079         *                     {@code false} for a retrieved or updated client.
080         */
081        public OIDCClientInformationResponse(final OIDCClientInformation clientInfo,
082                                             final boolean forNewClient) {
083
084                super(clientInfo, forNewClient);
085        }
086        
087        
088        /**
089         * Gets the OpenID Connect client information.
090         *
091         * @return The OpenID Connect client information.
092         */
093        public OIDCClientInformation getOIDCClientInformation() {
094
095                return (OIDCClientInformation)getClientInformation();
096        }
097        
098        
099        /**
100         * Parses an OpenID Connect client information response from the 
101         * specified HTTP response.
102         *
103         * @param httpResponse The HTTP response. Must not be {@code null}.
104         *
105         * @return The OpenID Connect client information response.
106         *
107         * @throws ParseException If the HTTP response couldn't be parsed to an
108         *                        OpenID Connect client information response.
109         */
110        public static OIDCClientInformationResponse parse(final HTTPResponse httpResponse)
111                throws ParseException {
112
113                httpResponse.ensureStatusCode(HTTPResponse.SC_OK, HTTPResponse.SC_CREATED);
114                OIDCClientInformation clientInfo = OIDCClientInformation.parse(httpResponse.getContentAsJSONObject());
115                boolean forNewClient = HTTPResponse.SC_CREATED == httpResponse.getStatusCode();
116                return new OIDCClientInformationResponse(clientInfo, forNewClient);
117        }
118}