daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Dec 19th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
  2.     {
  3.         var identity = new ClaimsIdentity(context.Options.AuthenticationType);
  4.         try
  5.         {
  6.             CreateDataConnection();
  7.             R_AuthenticateUser oAuthUser = oDataConnection.Authenticate(context.UserName,context.Password);
  8.             string DB_User_roles = oAuthUser.UserLoginRoles;
  9.  
  10.             if (oAuthUser.Authenticated)
  11.             {
  12.                 string[] aray = DB_User_roles.Split(',');
  13.  
  14.                 identity.AddClaim(new Claim(ClaimTypes.Name, oAuthUser.UserID.ToString()));                         // keeps the login_ID
  15.                 identity.AddClaim(new Claim(ClaimTypes.Email, context.UserName));
  16.  
  17.                 foreach (var item in aray)
  18.                 {
  19.           //          identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, item));
  20.                     identity.AddClaim(new Claim(ClaimTypes.Role, item));
  21.                 }
  22.                 context.Validated(identity);
  23.             }
  24.             else //if (context.UserName == "user" && context.Password == "user")
  25.             {
  26.                 context.SetError("Incorrect credntials", "Provided Username and Password is incorrect");
  27.                 return;
  28.             }
  29.         }
  30.         catch (Exception ex)
  31.         {
  32.             int y = 0;
  33.         }
  34.     }
  35.    
  36. [HttpGet]
  37. [PGAuthorization(Roles = "USER")]
  38. [Route("api/Address/GetAllAddresses")]
  39. public string GetAllAddressesByUser()
  40. {
  41.     CreateDataConnection();
  42.     Int64 UserID = Convert.ToInt64((User as ClaimsPrincipal).Identity.Name);
  43.     List<R_CustomerAddress> oUser = oDataConnection.GetAllAddressesByUser(UserID);
  44.     string output = JsonConvert.SerializeObject(oUser);
  45.     return output;
  46. }
  47.    
  48. Int64 UserID = Convert.ToInt64((User as ClaimsPrincipal).Identity.Email);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top