001package com.nimbusds.openid.connect.sdk.rp; 002 003 004import java.net.URL; 005import java.util.Date; 006 007import net.jcip.annotations.Immutable; 008 009import net.minidev.json.JSONObject; 010 011import com.nimbusds.oauth2.sdk.ParseException; 012import com.nimbusds.oauth2.sdk.auth.Secret; 013import com.nimbusds.oauth2.sdk.client.ClientInformation; 014import com.nimbusds.oauth2.sdk.client.ClientMetadata; 015import com.nimbusds.oauth2.sdk.id.ClientID; 016import com.nimbusds.oauth2.sdk.token.BearerAccessToken; 017import com.nimbusds.oauth2.sdk.util.JSONObjectUtils; 018 019 020/** 021 * OpenID Connect client information. Encapsulates the registration and 022 * metadata details of an OpenID Connect client: 023 * 024 * <ul> 025 * <li>The client identifier. 026 * <li>The client registration URI and access token. 027 * <li>The client OpenID Connect metadata. 028 * <li>The optional client secret for a confidential client. 029 * </ul> 030 * 031 * <p>This class is immutable. 032 * 033 * <p>Related specifications: 034 * 035 * <ul> 036 * <li>OpenID Connect Dynamic Client Registration 1.0. 037 * <li>OAuth 2.0 Dynamic Client Registration Protocol 038 * (draft-ietf-oauth-dyn-reg-14), section 2, 3.2 and 5.1. 039 * </ul> 040 * @author Vladimir Dzhuvinov 041 */ 042@Immutable 043public final class OIDCClientInformation extends ClientInformation { 044 045 046 /** 047 * Creates a new OpenID Connect client information instance. 048 * 049 * @param id The client identifier. Must not be 050 * {@code null}. 051 * @param registrationURI The client registration URI. Must not be 052 * {@code null}. 053 * @param accessToken The client registration access token. Must 054 * not be {@code null}. 055 * @param metadata The client metadata. Must not be 056 * {@code null}. 057 * @param secret The optional client secret, {@code null} if 058 * not specified. 059 * @param issueDate The issue date of the client identifier, 060 * {@code null} if not specified. 061 */ 062 public OIDCClientInformation(final ClientID id, 063 final URL registrationURI, 064 final BearerAccessToken accessToken, 065 final ClientMetadata metadata, 066 final Secret secret, 067 final Date issueDate) { 068 069 super(id, registrationURI, accessToken, metadata, secret, issueDate); 070 } 071 072 073 /** 074 * Gets the OpenID Connect client metadata. 075 * 076 * @return The OpenID Connect client metadata. 077 */ 078 public OIDCClientMetadata getOIDCClientMetadata() { 079 080 return (OIDCClientMetadata)getClientMetadata(); 081 } 082 083 084 /** 085 * Parses an OpenID Connect client information instance from the 086 * specified JSON object. 087 * 088 * @param jsonObject The JSON object to parse. Must not be 089 * {@code null}. 090 * 091 * @return The client information. 092 * 093 * @throws ParseException If the JSON object couldn't be parsed to an 094 * OpenID Connect client information instance. 095 */ 096 public static OIDCClientInformation parse(final JSONObject jsonObject) 097 throws ParseException { 098 099 ClientID id = new ClientID(JSONObjectUtils.getString(jsonObject, "client_id")); 100 101 102 URL registrationURI = JSONObjectUtils.getURL(jsonObject, "registration_client_uri"); 103 104 105 BearerAccessToken accessToken = new BearerAccessToken( 106 JSONObjectUtils.getString(jsonObject, "registration_access_token")); 107 108 109 OIDCClientMetadata metadata = OIDCClientMetadata.parse(jsonObject); 110 111 112 Secret secret = null; 113 114 if (jsonObject.containsKey("client_secret")) { 115 116 String value = JSONObjectUtils.getString(jsonObject, "client_secret"); 117 118 Date exp = null; 119 120 if (jsonObject.containsKey("client_secret_expires_at")) 121 exp = new Date(JSONObjectUtils.getLong(jsonObject, "client_secret_expires_at") * 1000); 122 123 secret = new Secret(value, exp); 124 } 125 126 127 Date issueDate = null; 128 129 if (jsonObject.containsKey("client_id_issued_at")) { 130 131 issueDate = new Date(JSONObjectUtils.getLong(jsonObject, "client_id_issued_at") * 1000); 132 } 133 134 135 return new OIDCClientInformation(id, registrationURI, accessToken, metadata, secret, issueDate); 136 } 137}