The main issue you have, is using Live ID (or, as they call it now - Microsoft Account). There is no way to get user's e-mail out from Live ID, if you just use ACS. I personally love ACS and use it, I just don't care about the Microsoft Account, or handle it in other ways.
If you want to restrict access to the whole application just for Admins, you have to accomplish two things:
- Setup Authorization rule in your
system.web
section that give access to only Administrator
role
- Setup Claim Rule in the ACS to generate
Administrator
role claim based on some input criteria.
Step one is fairly easy, just add the following inside your system.web
section in your web.config
file:
<authorization>
<allow roles="Administrator" />
<deny users="?" />
</authorization>
Just make sure there is no other authorization
section in your web.config!
Second step, the easy part.
Go your ACS management portal, then go the Rule Group which is assigned to your relying party application. And add a new Rule with the following criteria:
- Chose the Identity Provider for the rule (let's assume Google)
- Select the input Claim Type to be:
http://schemas.xmlsoap.org/claims/EmailAddress
- Enter Claim value:
your_desired_admin@gmail.com
(the e-mail address of Administrator)
- Select the output claim type to be:
http://schemas.microsoft.com/ws/2008/06/identity/claims/role
- Enter the value for the output claim:
Administrator
- Set proper description for the rule, something like
your_desired_admin@gmail.com is Administrator
.
- Save the rule.
Done. Repeat this step for all the persons you want to give Administrator permissions. Of course you can only do this for Identity Providers that will give you E-mail Address
. Sorry for Microsoft Account users.
There is no trivial way to give administrator permissions for a Microsoft Account holders when they come via Azure ACS. The only thing you have is a Name Identifier Claim, or http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier
(I will call it NIC
for simplicity.
NIC
is Unique on the following combination: User Identity (me@live.com)
+ ACS NameSpace
+ Relying Party Application
. This means that if me@live.com
log-ins to your app via mygreat.accesscontrol.windows.net
you will get a unique NIC
for that user. If the very same user log-ins to my site via someother.accesscontrol.windows.net
, I will get completely new NIC
, that will be globally unique again, but will not be the same as the one your application got.
And, as you can imagine, you cannot guess the NIC
for any user that comes from Live ID. Enabling this scenario for Live ID requires a bit more complicated logic. Which I don't have the time and space to describe here, but I might find a time for a nice blog post.
You can get the NameIdentifier claim on your application logic as already pointed out by Rick, but do you really want to give all and any users "Administrator" role? Plus, I would go away from leaving my application to mess with the Rules in ACS for every single login that comes. There are better ways to achieve what you want (as I said, time for blogging).