asp.net mvc - How to extend the Owin OAuth to accommodate the Application level login confirmation -
i working mvc5 application using owin oauth authentication. looking forward extend login criteria have added couple of tables (application table (applicationid(guid), applicationname(nvarchar) , applicationusertable(id, applicationid(fk application table), userid(fk column aspnetusers table))) in security db. please give me idea on how access applicationusertable in owin context can verify first if user belong particular application? have looked through quite few examples didn't find relevant particular scenario working with.
you set applicationid field clientid, have different clientid each application.
when user sends authentication token request, in grantresourceownercredentials
method when check user credentials, check if user belongs application received clientid represents.
in simple way, following:
public override async task grantresourceownercredentials(oauthgrantresourceownercredentialscontext context) { ... var user = await _userservice.getuserasync(context.username, context.password, context.clientid); if (user == null) { context.seterror("invalid_grant", "the user name, password or clientid incorrect."); return; } ... var ticket = new authenticationticket(identity, props); context.validated(ticket); }
and in user service:
public async task<user> getuserasync(string username, string password, string clientid = null) { var user = await _usermanager.findasync(username, password); if (user == null || (clientid != null && user.applicationusers.where(au => au.applicationid == clientid).count() == 0)) { return null; } return user; }
in validateclientauthentication
method should validate clientid-secret in application table.
i hope helps.
Comments
Post a Comment