001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2014-2016 ForgeRock AS.
015 */
016
017package org.forgerock.oauth2.core;
018
019import org.forgerock.oauth2.core.exceptions.InvalidClientException;
020import org.forgerock.oauth2.core.exceptions.NotFoundException;
021import org.forgerock.oauth2.core.exceptions.ServerException;
022import org.forgerock.openam.oauth2.OAuth2Constants.UrlLocation;
023
024import java.util.Map;
025import java.util.Set;
026
027/**
028 * Handles the issuing of Tokens for a response type, i.e. code, token, id_token.
029 *
030 * @since 12.0.0
031 * @supported.all.api
032 */
033public interface ResponseTypeHandler {
034
035    /**
036     * Handles the creating of a Token instance and storing the Token in the OAuth2 provider {@link TokenStore}.
037     *
038     * @param tokenType The type of the token.
039     * @param scope The requested scope.
040     * @param resourceOwner The resource owner.
041     * @param clientId The client's id.
042     * @param redirectUri The redirect uri.
043     * @param nonce The nonce.
044     * @param request The OAuth2 request.
045     * @param codeChallenge The code challenge.
046     * @param codeChallengeMethod The code challenge method.
047     * @return A {@code Map.Entry} of the token name with the Token instance.
048     * @throws ServerException If any internal server error occurs.
049     * @throws InvalidClientException If either the request does not contain the client's id or the client fails to be
050     *          authenticated.
051     * @throws NotFoundException If the realm does not have an OAuth 2.0 provider service.
052     */
053    Map.Entry<String, Token> handle(String tokenType, Set<String> scope, ResourceOwner resourceOwner,
054                                    String clientId, String redirectUri, String nonce, OAuth2Request request,
055                                    String codeChallenge, String codeChallengeMethod)
056            throws ServerException, InvalidClientException, NotFoundException;
057
058    /**
059     * Returns the location in which the token should be returned, {@link UrlLocation}.
060     *
061     * @return The UrlLocation.
062     */
063    UrlLocation getReturnLocation();
064}