summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdOfflineProvider/Controllers/HomeController.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-03-04 22:03:42 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2013-03-04 22:03:42 -0800
commitcb249022036daaebcccadf09d3c62410de3147b6 (patch)
tree3499d6dc917aa43e82a80020b227d32160ce2624 /samples/OpenIdOfflineProvider/Controllers/HomeController.cs
parentc1e5503b73929913e2c4ae59e0abe08f3d63736b (diff)
downloadDotNetOpenAuth-cb249022036daaebcccadf09d3c62410de3147b6.zip
DotNetOpenAuth-cb249022036daaebcccadf09d3c62410de3147b6.tar.gz
DotNetOpenAuth-cb249022036daaebcccadf09d3c62410de3147b6.tar.bz2
Moved Offline OP to use controllers.
Diffstat (limited to 'samples/OpenIdOfflineProvider/Controllers/HomeController.cs')
-rw-r--r--samples/OpenIdOfflineProvider/Controllers/HomeController.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/samples/OpenIdOfflineProvider/Controllers/HomeController.cs b/samples/OpenIdOfflineProvider/Controllers/HomeController.cs
new file mode 100644
index 0000000..f5a8763
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/Controllers/HomeController.cs
@@ -0,0 +1,54 @@
+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 Validation;
+
+ public class HomeController : ApiController {
+ public HttpResponseMessage Get() {
+ App.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<string>()), Encoding.UTF8, "application/xrds+xml"),
+ };
+ }
+
+ /// <summary>
+ /// Generates the OP Identifier XRDS document.
+ /// </summary>
+ /// <param name="providerEndpoint">The provider endpoint.</param>
+ /// <param name="supportedExtensions">The supported extensions.</param>
+ /// <returns>The content of the XRDS document.</returns>
+ private static string GenerateXrdsOPIdentifierDocument(Uri providerEndpoint, IEnumerable<string> supportedExtensions) {
+ Requires.NotNull(providerEndpoint, "providerEndpoint");
+ Requires.NotNull(supportedExtensions, "supportedExtensions");
+
+ const string OPIdentifierDiscoveryFormat = @"<xrds:XRDS
+ xmlns:xrds='xri://$xrds'
+ xmlns:openid='http://openid.net/xmlns/1.0'
+ xmlns='xri://$xrd*($v*2.0)'>
+ <XRD>
+ <Service priority='10'>
+ <Type>http://specs.openid.net/auth/2.0/server</Type>
+ {1}
+ <URI>{0}</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>";
+
+ string extensions = string.Join(
+ "\n\t\t\t",
+ supportedExtensions.Select(ext => "<Type>" + ext + "</Type>").ToArray());
+ return string.Format(
+ OPIdentifierDiscoveryFormat,
+ providerEndpoint.AbsoluteUri,
+ extensions);
+ }
+ }
+}