Clarity, Technology, and Solving Problems | PracticeThis.com
WP7 App with Key Windows Azure resources – Slides, Videos, How-To’s, and T-shooting – for quick consumption on the go.
LinkedIn
Windows Azure AppFabric Access Control Service (ACS) v2 has a feature called Error URL that allows a web site to display friendly message in case of error during the authentication/federation process. For example, during the authentication with Facebook or Google a user asked for consent after successful authentication. If the user denies ACS generates an error that could be presneted to a user in a friendly manner. Another case is when there is a mis-configuration at ACS level, for example, no rules generated for specific identity provider which results in error generated by ACS.
How to show friendly error message for these cases, branded with the look an feel as the rest of my website?
The solution is using Error URL feature available through ACS management portal. ACS generated JSON encoded error message and passes it to your error page. You need to specify the URL of the error page on ACS management portal so that ACS will know where to pass the information. Your error page should pars the JSON encoded error message and render appropriate HTML for the end user. Here is a sample JSON encoded error message:
{"context":null,"httpReturnCode":401,"identityProvider":"Google","timeStamp":"2010-12-17 21:01:36Z","traceId":"16bba464-03b9-48c6-a248-9d16747b1515","errors":[{"errorCode":"ACS30000","errorMessage":"There was an error processing an OpenID sign-in response."},{"errorCode":"ACS50019","errorMessage":"Sign-in was cancelled by the user."}]}
To process error messages from ACS complete these steps:
To enable Error URL feature for your relying party:
This step helps creating Error helpers classes for deserializing JSON encoded error messages.
To create Error Helper Classes:
public class Error { public string errorCode { get; set; } public string errorMessage { get; set; } }
public class ErrorDetails { public string context { get; set; } public int httpReturnCode { get; set; } public string identityProvider { get; set; } public Error[] errors { get; set; } }
To process JSON encoded error message generated by ACS:
<asp:Label ID="lblIdntityProvider" runat="server"></asp:Label>
<asp:Label ID="lblErrorMessage" runat="server"></asp:Label>
using System.Web.Script.Serialization;
JavaScriptSerializer serializer = new JavaScriptSerializer(); ErrorDetails error = serializer.Deserialize<ErrorDetails>( Request["ErrorDetails"] ); lblIdntityProvider.Text = error.identityProvider; lblErrorMessage.Text = string.Format("Error Code {0}: {1}", error.errors[0].errorCode, error.errors[0].errorMessage);
To configure anonymous access to the error page:
<location path="ErrorPage.aspx"> <system.web> <authorization> <allow users="*" /> </authorization> </system.web> </location>
To test Error URL feature:
uri:WindowsLiveID Error Code ACS50000: There was an error issuing a token.
Another way to test it is denying user consent. This is presented when you login using Facebook or Google.
Where is ErrorDetails defined?
Luke, good catch.
These are helper classes used to parse JSON encoded error messages.
I updated the post accordingly.
Thank you for the feedback.
Thank you for the prompt reply.
Actually ACS returns array of errors. I used the following code to display all the errors.
lblErrorMessage.Text = string.Join("<br/>", error.errors.Select(er => string.Format("Error Code {0}: {1}", er.errorCode, er.errorMessage)).ToArray());
I am creating a custom STS by using WIF. I used a self signing certificate for creating the token. ACS is not happy with the token created from my custom STS. What should I do so that ACS can accept the token created from my custom STS? Is a way to disable STS signing certificate validation?
Error Code ACS20001: An error occurred while processing a WS-Federation sign-in response.
Error Code ACS50008: SAML token is invalid.
Error Code ACS50008: Invalid SAML token. The issuer name is invalid.
Luke, please submit this question to ACS Discussion list here:
acs.codeplex.com/discussions
or on Claims Based Access forum here:
social.msdn.microsoft.com/.../threads
+ I liked how you modified the code for errors collections