//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenIdOfflineProvider.Controllers {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using DotNetOpenAuth.Logging;
using Validation;
public class HomeController : ApiController {
private static readonly ILog Logger = LogProvider.GetCurrentClassLogger();
public HttpResponseMessage Get() {
Logger.Info("Discovery on OP Identifier detected.");
var opEndpoint = this.Url.Link("default", new { controller = "provider" });
var opEndpointUri = new Uri(opEndpoint);
return new HttpResponseMessage() {
Content = new StringContent(GenerateXrdsOPIdentifierDocument(opEndpointUri, Enumerable.Empty()), Encoding.UTF8, "application/xrds+xml"),
};
}
///
/// Generates the OP Identifier XRDS document.
///
/// The provider endpoint.
/// The supported extensions.
/// The content of the XRDS document.
private static string GenerateXrdsOPIdentifierDocument(Uri providerEndpoint, IEnumerable supportedExtensions) {
Requires.NotNull(providerEndpoint, "providerEndpoint");
Requires.NotNull(supportedExtensions, "supportedExtensions");
const string OPIdentifierDiscoveryFormat = @"
http://specs.openid.net/auth/2.0/server
{1}
{0}
";
string extensions = string.Join(
"\n\t\t\t",
supportedExtensions.Select(ext => "" + ext + "").ToArray());
return string.Format(
OPIdentifierDiscoveryFormat,
providerEndpoint.AbsoluteUri,
extensions);
}
}
}