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.oauth2.sdk.client; 019 020 021import net.jcip.annotations.Immutable; 022 023import com.nimbusds.oauth2.sdk.ParseException; 024import com.nimbusds.oauth2.sdk.SuccessResponse; 025import com.nimbusds.oauth2.sdk.http.CommonContentTypes; 026import com.nimbusds.oauth2.sdk.http.HTTPResponse; 027 028 029/** 030 * Client information response. 031 * 032 * <p>Example HTTP response: 033 * 034 * <pre> 035 * HTTP/1.1 200 OK 036 * Content-Type: application/json 037 * Cache-Control: no-store 038 * Pragma: no-cache 039 * 040 * { 041 * "registration_access_token" : "reg-23410913-abewfq.123483", 042 * "registration_client_uri" : "https://server.example.com/register/s6BhdRkqt3", 043 * "client_id" : "s6BhdRkqt3", 044 * "client_secret" : "cf136dc3c1fc93f31185e5885805d", 045 * "client_id_issued_at" : 2893256800 046 * "client_secret_expires_at" : 2893276800 047 * "client_name" : "My Example Client", 048 * "client_name#ja-Jpan-JP" : "\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\u540D", 049 * "redirect_uris" : [ "https://client.example.org/callback", 050 * "https://client.example.org/callback2" ] 051 * "scope" : "read write dolphin", 052 * "grant_types" : [ "authorization_code", "refresh_token" ] 053 * "token_endpoint_auth_method" : "client_secret_basic", 054 * "logo_uri" : "https://client.example.org/logo.png", 055 * "jwks_uri" : "https://client.example.org/my_public_keys.jwks" 056 * } 057 * </pre> 058 * 059 * <p>Related specifications: 060 * 061 * <ul> 062 * <li>OAuth 2.0 Dynamic Client Registration Management Protocol (RFC 063 * 7592), section 3.1. 064 * <li>OAuth 2.0 Dynamic Client Registration Protocol (RFC 7591), section 065 * 3.2.1. 066 * </ul> 067 */ 068@Immutable 069public class ClientInformationResponse 070 extends ClientRegistrationResponse 071 implements SuccessResponse { 072 073 074 /** 075 * The client information. 076 */ 077 private ClientInformation clientInfo; 078 079 080 /** 081 * Creates a new client information response. 082 * 083 * @param clientInfo The client information. Must not be {@code null}. 084 */ 085 public ClientInformationResponse(final ClientInformation clientInfo) { 086 087 if (clientInfo == null) 088 throw new IllegalArgumentException("The client information must not be null"); 089 090 this.clientInfo = clientInfo; 091 } 092 093 094 @Override 095 public boolean indicatesSuccess() { 096 097 return true; 098 } 099 100 101 /** 102 * Gets the client information. 103 * 104 * @return The client information. 105 */ 106 public ClientInformation getClientInformation() { 107 108 return clientInfo; 109 } 110 111 112 @Override 113 public HTTPResponse toHTTPResponse() { 114 115 HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_OK); 116 httpResponse.setContentType(CommonContentTypes.APPLICATION_JSON); 117 httpResponse.setCacheControl("no-store"); 118 httpResponse.setPragma("no-cache"); 119 httpResponse.setContent(clientInfo.toJSONObject().toString()); 120 return httpResponse; 121 } 122 123 124 /** 125 * Parses a client information response from the specified 126 * HTTP response. 127 * 128 * @param httpResponse The HTTP response. Must not be {@code null}. 129 * 130 * @return The client information response. 131 * 132 * @throws ParseException If the HTTP response couldn't be parsed to a 133 * client information response. 134 */ 135 public static ClientInformationResponse parse(final HTTPResponse httpResponse) 136 throws ParseException { 137 138 httpResponse.ensureStatusCode(HTTPResponse.SC_OK, HTTPResponse.SC_CREATED); 139 ClientInformation clientInfo = ClientInformation.parse(httpResponse.getContentAsJSONObject()); 140 return new ClientInformationResponse(clientInfo); 141 } 142}