Autherization using OAuth in MVC

  

Scenario:

User Authorization using OAuth for MVC

Solution:

         MVC Authorization Filter
    1
    2
    3
    4
    5
    6
    7
        public class AuthorizeFilter : ActionFilterAttribute
        { 
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                Authorized(UserId, token, Controller, Action, "Get");
            }
        }
          Authorization Service, internally calling OAuth service
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
        public class AuthServ
        {
            public bool Authorized(request)
            {
                var claims = GetClaims(user, token);
    
                if (claims.ContainsKey(claimRequested))
                {
                    return true;
                }
                return false;
            }
    
            public Claims GetClaims(string user, string token)
            {
                var webClient = new WebClient();
                webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
    
                return webClient.UploadString("/TokenProvider/GetCustomerRoles?grant_type=role&Token={token}", "POST", "");
            }
        }

No comments:

Post a Comment

Move Github Sub Repository back to main repo

 -- delete .gitmodules git rm --cached MyProject/Core git commit -m 'Remove myproject_core submodule' rm -rf MyProject/Core git remo...