com.authlete.common.dto.UserInfoIssueRequest Maven / Gradle / Ivy
/*
* Copyright (C) 2015-2016 Authlete, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.authlete.common.dto;
import java.io.Serializable;
import java.util.Map;
import com.authlete.common.util.Utils;
/**
* Request to Authlete's {@code /auth/userinfo/issue} API.
*
*
*
* token
(REQUIRED)
* -
*
* The access token that has been passed to the service's userinfo endpoint by the client application. In other words,
* the access token which was contained in the userinfo request.
*
*
*
* claims
(OPTIONAL)
* -
*
* Claims in JSON format. As for the format, see {@link #setClaims(String)}
* and "OpenID Connect Core 1.0, 5.1. Standard Claims".
*
*
*
* sub
(OPTIONAL)
* -
*
* The value of the {@code sub} claim. If the value of this request parameter
* is not empty, it is used as the value of the 'sub' claim. Otherwise, the
* value of the subject associated with the access token is used.
*
*
*
*
*
* @author Takahiko Kawasaki
*/
public class UserInfoIssueRequest implements Serializable
{
private static final long serialVersionUID = 4L;
/**
* The access token.
*/
private String token;
/**
* Claims in JSON format.
*/
private String claims;
/**
* The value of the 'sub' claim. If this field is empty, the value of
* the subject that is associated with the access token is used as the
* value of the 'sub' claim.
*/
private String sub;
/**
* Get the access token which has come along with the userinfo
* request from the client application.
*/
public String getToken()
{
return token;
}
/**
* Set the access token which has been issued by Authlete.
* The access token is the one that has come along with the
* userinfo request from the client application.
*/
public UserInfoIssueRequest setToken(String token)
{
this.token = token;
return this;
}
/**
* Get the claims of the subject in JSON format.
*
* @return
* The claims of the subject in JSON format. See the description
* of {@link #setClaims(String)} for details about the format.
*
* @see #setClaims(String)
*/
public String getClaims()
{
return claims;
}
/**
* Set the claims of the subject in JSON format.
*
*
* The service implementation is required to retrieve claims of the subject
* (= information about the end-user) from its database and format them in
* JSON format.
*
*
*
* For example, if "given_name"
claim, "family_name"
* claim and "email"
claim are requested, the service implementation
* should generate a JSON object like the following:
*
*
*
* {
* "given_name": "Takahiko",
* "family_name": "Kawasaki",
* "email": "[email protected]"
* }
*
*
*
* and set its String representation by this method.
*
*
*
* See OpenID Connect Core 1.0, 5.1. Standard Claims for further details
* about the format.
*
*
* @param claims
* The claims of the subject in JSON format.
*
* @return
* {@code this} object.
*
* @see OpenID Connect Core 1.0, 5.1. Standard Claims
*/
public UserInfoIssueRequest setClaims(String claims)
{
this.claims = claims;
return this;
}
/**
* Set the value of {@code "claims"} which is the claims of the subject.
* The argument is converted into a JSON string and passed to {@link
* #setClaims(String)} method.
*
* @param claims
* The claims of the subject. Keys are claim names.
*
* @return
* {@code this} object.
*
* @since 1.24
*/
public UserInfoIssueRequest setClaims(Map claims)
{
if (claims == null || claims.size() == 0)
{
this.claims = null;
return this;
}
String json = Utils.toJson(claims);
return setClaims(json);
}
/**
* Get the value of the {@code sub} claim. If this method returns a non-empty value,
* it is used as the value of the 'sub' claim. Otherwise, the value of the subject
* associated with the access token is used.
*
* @return
* The value of the {@code sub} claim.
*
* @since 1.35
*/
public String getSub()
{
return sub;
}
/**
* Set the value of the {@code sub} claim. If a non-empty value is given, it is
* used as the value of the 'sub' claim. Otherwise, the value of the subject
* associated with the access token is used.
*
* @param sub
* The value of the {@code sub} claim.
*
* @return
* {@code this} object.
*
* @since 1.35
*/
public UserInfoIssueRequest setSub(String sub)
{
this.sub = sub;
return this;
}
}