summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdOfflineProvider/Controllers/UserController.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-03-26 11:19:06 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2013-03-26 11:19:06 -0700
commit3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb (patch)
treec15816c3d7f6e74334553f2ff98605ce1c22c538 /samples/OpenIdOfflineProvider/Controllers/UserController.cs
parent5e9014f36b2d53b8e419918675df636540ea24e2 (diff)
parente6f7409f4caceb7bc2a5b4ddbcb1a4097af340f2 (diff)
downloadDotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.zip
DotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.tar.gz
DotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.tar.bz2
Move to HttpClient throughout library.
Diffstat (limited to 'samples/OpenIdOfflineProvider/Controllers/UserController.cs')
-rw-r--r--samples/OpenIdOfflineProvider/Controllers/UserController.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/samples/OpenIdOfflineProvider/Controllers/UserController.cs b/samples/OpenIdOfflineProvider/Controllers/UserController.cs
new file mode 100644
index 0000000..9385b7f
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/Controllers/UserController.cs
@@ -0,0 +1,49 @@
+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 UserController : ApiController {
+ public HttpResponseMessage Get(string id) {
+ string localId = null; // string.Format("http://localhost:{0}/user", context.Request.Url.Port);
+ var opEndpoint = this.Url.Link("default", new { controller = "provider" });
+ var opEndpointUri = new Uri(opEndpoint);
+ return new HttpResponseMessage() {
+ Content = new StringContent(GenerateHtmlDiscoveryDocument(opEndpointUri, localId), Encoding.UTF8, "text/html"),
+ };
+ }
+
+ /// <summary>
+ /// Generates HTML for an identity page.
+ /// </summary>
+ /// <param name="providerEndpoint">The provider endpoint.</param>
+ /// <param name="localId">The local id.</param>
+ /// <returns>The HTML document to return to the RP.</returns>
+ private static string GenerateHtmlDiscoveryDocument(Uri providerEndpoint, string localId) {
+ Requires.NotNull(providerEndpoint, "providerEndpoint");
+
+ const string DelegatedHtmlDiscoveryFormat = @"<html><head>
+ <link rel=""openid.server"" href=""{0}"" />
+ <link rel=""openid.delegate"" href=""{1}"" />
+ <link rel=""openid2.provider"" href=""{0}"" />
+ <link rel=""openid2.local_id"" href=""{1}"" />
+ </head><body></body></html>";
+
+ const string NonDelegatedHtmlDiscoveryFormat = @"<html><head>
+ <link rel=""openid.server"" href=""{0}"" />
+ <link rel=""openid2.provider"" href=""{0}"" />
+ </head><body></body></html>";
+
+ return string.Format(
+ localId != null ? DelegatedHtmlDiscoveryFormat : NonDelegatedHtmlDiscoveryFormat,
+ providerEndpoint.AbsoluteUri,
+ localId);
+ }
+ }
+}