{"id":2518,"date":"2013-10-26T00:27:33","date_gmt":"2013-10-26T07:27:33","guid":{"rendered":"http:\/\/www.cloudidentity.com\/blog\/?p=2518"},"modified":"2013-10-26T01:01:51","modified_gmt":"2013-10-26T08:01:51","slug":"you-have-to-sign-up-with-your-own-multiple-organizations-asp-net-app-before-you-can-sign-in","status":"publish","type":"post","link":"https:\/\/www.cloudidentity.com\/blog\/2013\/10\/26\/you-have-to-sign-up-with-your-own-multiple-organizations-asp-net-app-before-you-can-sign-in\/","title":{"rendered":"You Have to Sign Up With Your Own Multiple Organizations ASP.NET App Before You Can Sign In"},"content":{"rendered":"<p>Well, I\u2019ve basically wrote most of the post already in the extra-long title! <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" style=\"border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/wlEmoticon-smile5.png\"><\/p>\n<p>The ASP.NET project templates in VS2013 for multiple organizations apps contain a design choice which appears to be causing grief to many developers. In this post I am going to describe the issue (and show you how to make it a non-issue) \u2013 for the longer term I guess that the default behavior might have to be changed <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" style=\"border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/wlEmoticon-smile5.png\"><\/p>\n<h2>The Issue<\/h2>\n<p>The issue is easily explained. If you follow this blog, you already know that the ASP.NET project creation in VS2013 offers you the chance of configuring projects for various authentication styles for business apps. <br \/>One of the available templates generates one application meant to be consumed by multiple organizations: if you like buzzwords, that\u2019s what you\u2019d call a SaaS app or a multi-tenant app.<\/p>\n<p>Those apps are meant to accept users from multiple organizations, and more precisely from multiple Windows Azure AD tenants. The template code contains logic for onboarding new organizations: it boils down to triggering the consent flow which allows a the admin of a prospective customer to instantly grant to the application access to his\/her own tenant. The application template provides a database which is used to maintain the list of organizations that have been onboarded; such database is used at sign in time to establish if the incoming user belongs to one of the onboarded tenants. The template contains logic for processing messages about successful onboardings by adding the corresponding organization in the database.<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image31.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image_thumb31.png\" width=\"375\" height=\"246\"><\/a><\/p>\n<p>Here there\u2019s the thing that is causing the issue for some of you: <em>at creation time, that database is empty<\/em>. <\/p>\n<p>Technically, when you create a multiple organizations app entry in Windows Azure AD you are doing two operations at once: creating the Application object which describes the app, and consenting for that app to use your directory (e.g. creating a service principal for it in your directory). For a deep dive on the application model, see <a href=\"https:\/\/www.cloudidentity.com\/blog\/2013\/04\/16\/the-windows-azure-ad-application-model\/\">here<\/a>.<br \/>However, the VS template does NOT reflect the fact that your app is automatically provisioned in your own tenant. There is a reason for that: your application might call for some extra provisioning operations every time you onboard a new customer organization, and pre-provisioning a tenant in the DB would create an odd situation as your extra provisioning logic would have never a chance to run. <\/p>\n<p>Regardless of the reason, this creates a problem for the ones among you who follow this rather natural sequence:<\/p>\n<ul>\n<li>you create the app<\/li>\n<li>you hit F5 right away<\/li>\n<li>once presented with the home screen (shown below) you hit sign in and you enter the credentials of your user in your development tenant<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image32.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image_thumb32.png\" width=\"634\" height=\"480\"><\/a><\/p>\n<ul>\n<li>after you entered your credentials, you are promptly welcomed by the error below<\/li>\n<\/ul>\n<blockquote>\n<h3>Server Error in &#8216;\/&#8217; Application. <\/h3>\n<h3>\n<hr size=\"1\" width=\"100%\"> <\/h3>\n<h4><i>WIF10201: No valid key mapping found for securityToken: &#8216;System.IdentityModel.Tokens.X509SecurityToken&#8217; and issuer: &#8216;https:\/\/sts.windows.net\/6133e43d-b70d-40ca-87c0-f16993f99070\/&#8217;.<\/i><\/h4>\n<p><b>Description: <\/b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br \/><b>Exception Details: <\/b>System.IdentityModel.Tokens.SecurityTokenValidationException: WIF10201: No valid key mapping found for securityToken: &#8216;System.IdentityModel.Tokens.X509SecurityToken&#8217; and issuer: &#8216;https:\/\/sts.windows.net\/6133e43d-b70d-40ca-87c0-f16993f99070\/&#8217;.<br \/><b>Source Error:<\/b>  <\/p>\n<p><code>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.<\/code>  <\/p>\n<p><b>Stack Trace:<\/b>  <\/p>\n<p><code><\/p>\n<pre>[SecurityTokenValidationException: WIF10201: No valid key mapping found for securityToken: 'System.IdentityModel.Tokens.X509SecurityToken' and issuer: 'https:\/\/sts.windows.net\/6133e43d-b70d-40ca-87c0-f16993f99070\/'.]\r\n   System.IdentityModel.Tokens.Saml2SecurityTokenHandler.ValidateToken(SecurityToken token) +867\r\n   System.IdentityModel.Tokens.SecurityTokenHandlerCollection.ValidateToken(SecurityToken token) +73\r\n   System.IdentityModel.Services.TokenReceiver.AuthenticateToken(SecurityToken token, Boolean ensureBearerToken, String endpointUri) +299\r\n   System.IdentityModel.Services.WSFederationAuthenticationModule.SignInWithResponseMessage(HttpRequestBase request) +917\r\n   System.IdentityModel.Services.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs args) +464\r\n   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136\r\n   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +69\r\n<\/pre>\n<p><\/code><\/p>\n<hr size=\"1\" width=\"100%\">\n<b>Version Information:<\/b> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.33440 <\/p><\/blockquote>\n<p>That is basically telling you that your tenant has no entry in the local database, hence you are not supposed to access the application.<\/p>\n<h2>The Solution<\/h2>\n<p>The solution is super straightforward: you just need to use the template logic itself to sign up your own tenant. Click on the \u201cSign up for this application\u201d link on the top bar. You\u2019ll get to the following page:<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image33.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image_thumb33.png\" width=\"625\" height=\"480\"><\/a><\/p>\n<p>Hit Sign Up. Authenticate as one admin of your development tenant. You\u2019ll land on the following page:<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image34.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image_thumb34.png\" width=\"624\" height=\"480\"><\/a><\/p>\n<blockquote>\n<p>Now, this would be a good place for warning you about a small issue\u2026 if you are on Windows 8.1 &amp; IE11, chances are that hitting \u201cgrant access\u201d will trigger the following JavaScript error:<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image35.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image_thumb35.png\" width=\"318\" height=\"283\"><\/a><\/p>\n<p>The portal guys are going to fix this issue soon, but in the meanwhile you can work around this by adding this page in the Compatibility View list of IE11. Hit Alt+T, select Compatibility View Settings, and click the Add button to add windowsazure.com in the compatibility view list. The page will reload and you\u2019ll be all set.<\/p>\n<\/blockquote>\n<p>Hit \u201cgrant access\u201d. You\u2019ll be redirected back to your app:<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image36.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image_thumb36.png\" width=\"629\" height=\"480\"><\/a><\/p>\n<p>That\u2019s it. Your tenant is now in the DB and you can sign in:<\/p>\n<p><a href=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image37.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/image_thumb37.png\" width=\"621\" height=\"480\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>All done. In just 3 clicks and one authentication you are all set. <br \/>Granted, the one among you stumbling on this would likely rather have the development tenant pre-populated by default in the database right out of the gate\u2026 my understanding is that this is pretty high in the list of things to change, but of course your feedback can help <img decoding=\"async\" class=\"wlEmoticon wlEmoticon-smile\" style=\"border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none\" alt=\"Smile\" src=\"https:\/\/www.cloudidentity.com\/blog\/wp-content\/uploads\/2013\/10\/wlEmoticon-smile5.png\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well, I\u2019ve basically wrote most of the post already in the extra-long title! The ASP.NET project templates in VS2013 for multiple organizations apps contain a design choice which appears to be causing grief to many developers. In this post I am going to describe the issue (and show you how to make it&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2505,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2518","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/2518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/comments?post=2518"}],"version-history":[{"count":2,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/2518\/revisions"}],"predecessor-version":[{"id":2521,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/2518\/revisions\/2521"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media\/2505"}],"wp:attachment":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media?parent=2518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/categories?post=2518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/tags?post=2518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}