Bart Calixto
Bart Calixto

Reputation: 19725

What's the practical workflow using claims for authentication and authorization in a web application?

I just don't still get Claim Based Authentication/Authorization workflow.

The application allows authentication via Facebook.com

After the user is authenticated, an admin can give her/him a claim of having the role of Manager, which creates another claim (where?)

Of course, this claim won't be on the facebook.com server, question 1: where should that claim be stored?

When the user log in again later, I get the claim of facebook.com and I should get the claim from the application. and merge them?

How is the workflow? Trying to understand claims in practical usage.

Basically, Facebook tells me that I'm [email protected], and 'field in the blanks' adds a claim that I'm also a manager of domain.com

then I pass those claims to domain.com?

How should I configure in asp.net the application at domain.com to trust Facebook and 'filled in the blank piece' and request claims from both?

I guess I'm using external providers for Authentication and my own provider for Authorization, how this is created on ASP.NET (web API / MVC)?

UPDATE (for clarification)

Let's get backwards. I create a web application where users can register. 'Somehow' there's an trusted ClaimsBased authority somewhere (this should be another application??) where I request the claims for a particular user to see if have particular rights on my application.

So I imagine something like :

/authserver/claims

and my validation checks if X claim is met to do certain operations.

later I add to Facebook. now I have

/facebook/claims

which tells me the user is X and

/authserver/claims to see if can do operation X on resource Y.

how this is managed on ASP.NET? and where my own claims should be created/exposed/developed.

I think I'm missing something fundamental here.

Upvotes: 4

Views: 1215

Answers (2)

Erik Philips
Erik Philips

Reputation: 54638

I think the important thing to understand is the difference between authentication and authorization.

Authentication - the act of confirming the truth of an attribute of a datum or entity.

Authorization - the function of specifying access rights to resources, which is related to information security and computer security in general and to access control in particular.

So, typically for secured system, the workflow starts with Authentication. When a user first connects/uses a system, then are not authenticated (lets say this user is of a type/group Anonymous). The act of the system determining the user is not authenticated is an Authentication in and of it self. Based on being Anonymous, then the act of the system determining what that type of user anonymous has access too is now authorizing what the user can do. For very secure system, the only access anonymous has is to the login screen/page. Once logged in the user is assigned a unique identity and assigned some type of group policy/role (if not already created). with a web-based application and having a website (#1) authenticate for another website(#2) it becomes a bit more complicated. When I log into StackOverflow(#1), I use my Gmail(#2) account. I get redirected to Google with some special way for Google to know that the page I came from/to go back to. This could be a special key/url combination or for less restrictive access, usually has to do with return url (after I say, yes, where I go back too). Google will create a special authentication token that is specific to the url I am returning to. It is tied to the URL because that means that my token on StackOverflow won't allow me or anyone else to log into say NewEgg for example (in other words someone at StackOverflow with access to the database can't use my token to authenticate as me on some other website, but technically they could log in as me on StackOverflow, but they own the website, so that doesn't really matter). Now I am authenticated on StackOverflow (but technically StackOverflow doesn't even need to know any information about me, just my Token).

On StackOverflow as a new user, a new account is created. This account probably has a one to many relationship to my unique account on Stack Overflow and multiple of logins (and type of logins, OAuth, OpenID or SO Login). Once the account is created, I have whatever access they have setup by default. If I need more or some trigger (lets say based on my Reputation points :) I now have access to Administrative functionality (given some role). That role is tied to my account and indirectly tied to my authentication. This means that I can create additional logins (say a Local SO Login) but keep my Account.

As for each Authentication resource (Google, Facebook, etc) there will be difference schemes for Authentication, but there will always be at least a token (or more than one token) for a website to say who I am (in a generic way).

So website #1 (Stack Overflow) has requested website #2 (Google) to Authenticate me. But only website #1 knows what am I Authorized for.

For role specific functionality, there are a good number of answer on SO dealing with ASP.Net Identity and the Role Manager:

Creating Roles in Asp.net Identity MVC 5

mvc 5 check user role

A much more Indepth look into Identity with MVC - Extending Identity Accounts and Implementing Role-Based Authentication in ASP.NET MVC 5

Upvotes: 1

Brendan Green
Brendan Green

Reputation: 11944

If you're using ASPNET.Identity (http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity), you can add a Role claim type to the user. It'll be associated with the userlogin, so when the user authenticates with Facebook, these user claims will be added and available in MVC.

See the following code fragment:

var acRes = await UserManager.AddClaimAsync(userId, new Claim(ClaimTypes.Role, "MyRole"));

Upvotes: 0

Related Questions