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 Management Protocol 046 * (draft-ietf-oauth-dyn-reg-management-12), section 3.1. 047 * <li>OAuth 2.0 Dynamic Client Registration Protocol 048 * (draft-ietf-oauth-dyn-reg-27), section 3.2.1. 049 * </ul> 050 */ 051@Immutable 052public class ClientInformationResponse 053 extends ClientRegistrationResponse 054 implements SuccessResponse { 055 056 057 /** 058 * The client information. 059 */ 060 private ClientInformation clientInfo; 061 062 063 /** 064 * Creates a new client information response. 065 * 066 * @param clientInfo The client information. Must not be {@code null}. 067 */ 068 public ClientInformationResponse(final ClientInformation clientInfo) { 069 070 if (clientInfo == null) 071 throw new IllegalArgumentException("The client information must not be null"); 072 073 this.clientInfo = clientInfo; 074 } 075 076 077 @Override 078 public boolean indicatesSuccess() { 079 080 return true; 081 } 082 083 084 /** 085 * Gets the client information. 086 * 087 * @return The client information. 088 */ 089 public ClientInformation getClientInformation() { 090 091 return clientInfo; 092 } 093 094 095 @Override 096 public HTTPResponse toHTTPResponse() { 097 098 HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_OK); 099 httpResponse.setContentType(CommonContentTypes.APPLICATION_JSON); 100 httpResponse.setCacheControl("no-store"); 101 httpResponse.setPragma("no-cache"); 102 httpResponse.setContent(clientInfo.toJSONObject().toString()); 103 return httpResponse; 104 } 105 106 107 /** 108 * Parses a client information response from the specified 109 * HTTP response. 110 * 111 * @param httpResponse The HTTP response. Must not be {@code null}. 112 * 113 * @return The client information response. 114 * 115 * @throws ParseException If the HTTP response couldn't be parsed to a 116 * client information response. 117 */ 118 public static ClientInformationResponse parse(final HTTPResponse httpResponse) 119 throws ParseException { 120 121 httpResponse.ensureStatusCode(HTTPResponse.SC_OK, HTTPResponse.SC_CREATED); 122 ClientInformation clientInfo = ClientInformation.parse(httpResponse.getContentAsJSONObject()); 123 return new ClientInformationResponse(clientInfo); 124 } 125}