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