コード例 #1
0
ファイル: AccountController.cs プロジェクト: kaban4ik1994/TWC
		public async Task<IHttpActionResult> Get()
		{
			AuthRepository auth = new AuthRepository();
			var user = await auth.RegisterUser("test", "123123123");
			var a = await auth.FindUser("test", "123123123");
			return Ok(a);
		}
コード例 #2
0
		public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
		{

			var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin") ?? "*";

			context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

			using (var repo = new AuthRepository())
			{
				IdentityUser user = await repo.FindUser(context.UserName, context.Password);

				if (user == null)
				{
					context.SetError("invalid_grant", "The user name or password is incorrect.");
					return;
				}
			}

			var identity = new ClaimsIdentity(context.Options.AuthenticationType);
			identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
			identity.AddClaim(new Claim(ClaimTypes.Role, "user"));
			identity.AddClaim(new Claim("sub", context.UserName));

			var props = new AuthenticationProperties(new Dictionary<string, string>
                {
                    { 
                        "as:client_id", (context.ClientId == null) ? string.Empty : context.ClientId
                    },
                    { 
                        "userName", context.UserName
                    }
                });

			var ticket = new AuthenticationTicket(identity, props);
			context.Validated(ticket);

		}