001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2016, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.oauth2.sdk.as;
019
020
021import java.net.MalformedURLException;
022import java.net.URI;
023import java.net.URL;
024
025import com.nimbusds.oauth2.sdk.AbstractRequest;
026import com.nimbusds.oauth2.sdk.SerializeException;
027import com.nimbusds.oauth2.sdk.http.HTTPRequest;
028import com.nimbusds.oauth2.sdk.id.Issuer;
029import com.nimbusds.oauth2.sdk.util.URIUtils;
030import net.jcip.annotations.Immutable;
031
032
033/**
034 * OAuth 2.0 Authorisation Server (AS) configuration request.
035 *
036 * <p>Example HTTP request:
037 *
038 * <pre>
039 * GET /.well-known/oauth-authorization-server HTTP/1.1
040 * Host: example.com
041 * </pre>
042 *
043 * <p>Related specifications:
044 *
045 * <ul>
046 *     <li>OAuth 2.0 Authorization Server Metadata 
047 *         (draft-ietf-oauth-discovery-10)
048 * </ul>
049 */
050@Immutable
051public class AuthorizationServerConfigurationRequest extends AbstractRequest {
052        
053        
054        /**
055         * The well-known path for OAuth 2.0 Authorisation Server metadata.
056         */
057        public static final String OAUTH_SERVER_WELL_KNOWN_PATH = "/.well-known/oauth-authorization-server";
058        
059        
060        /**
061         * Creates a new OAuth 2.0 Authorisation Server configuration request.
062         *
063         * @param issuer The issuer. Must represent a valid URL.
064         */
065        public AuthorizationServerConfigurationRequest(final Issuer issuer) {
066                super(URI.create(URIUtils.removeTrailingSlash(URI.create(issuer.getValue())) + OAUTH_SERVER_WELL_KNOWN_PATH));
067        }
068        
069        
070        @Override
071        public HTTPRequest toHTTPRequest() {
072                
073                URL url;
074                
075                try {
076                        url = getEndpointURI().toURL();
077                        
078                } catch (IllegalArgumentException | MalformedURLException e) {
079                        
080                        throw new SerializeException(e.getMessage(), e);
081                }
082                
083                return new HTTPRequest(HTTPRequest.Method.GET, url);
084        }
085}