12

tôi có một giải pháp asp.net trong đó bao gồmasp.net web form khách hàng với máy chủ bản sắc 4

1). asp.net identity server rc 3 
2). asp.net Core web api 
3). asp.net webform (not in asp.net core, client) 

Tôi không thấy bất kỳ mẫu với máy chủ bản sắc 4 và mẫu web client. Bạn có thể vui lòng đề xuất cách xác thực người dùng biểu mẫu web bằng máy chủ nhận dạng với danh tính asp.net và sau đó gọi api bằng mã thông báo truy cập không?

Tôi không thấy máy chủ danh tính 4 mẫu với web form client hoặc sample

máy chủ danh tính 3 có một sample nhưng nó đang làm tất cả mọi thứ trong startup

Khi tôi thấy mvc client cho máy chủ nhận diện 4, nó có tất cả cài đặt trong phương thức cấu hình và sau đó gọi nó là this

Làm thế nào tôi sẽ áp dụng thuộc tính ủy quyền trong biểu mẫu web để tôi được chuyển hướng đến máy chủ nhận dạng 4 để đăng nhập và sau đó đăng nhập khi tôi gọi api như thế này:

cách thay đổi ứng dụng khách cho biểu mẫu web?

new Client() 
        { 
        ClientId = "mvcClient", 
        ClientName = "MVC Client",      
        AllowedGrantTypes = GrantTypes.HybridAndClientCredentials, 

        ClientSecrets = new List<Secret>() 
        { 
         new Secret("secret".Sha256()) 
        }, 

        RequireConsent = false; 

        // where to redirect to after login 
        RedirectUris = { "http://localhost:5002/signin-oidc" }, 
        // where to redirect to after logout 
        PostLogoutRedirectUris = { "http://localhost:5002" }, 

        AllowedScopes = 
        { 
         StandardScopes.OpenId.Name, 
         StandardScopes.Profile.Name, 
         StandardScopes.OfflineAccess.Name, 
         StandardScopes.Roles.Name, 
         "API" 
        } 
       } 

new InMemoryUser() 
      { 
       Subject = "1", 
       Username = "testuser", 
       Password = "password", 
       Claims = new List<Claim>() 
       { 
        new Claim("name", "Alice"), 
        new Claim("Website", "http://alice.com"), 
        new Claim(JwtClaimTypes.Role, "admin") 

       } 
      } 


return new List<Scope>() 
       { 
        StandardScopes.OpenId, // subject id 
        StandardScopes.Profile, // first name, last name 
        StandardScopes.OfflineAccess, 
        StandardScopes.Roles, 
        new Scope() 
        { 
         Name = "API", 
         Description = "API desc", 
         Type = ScopeType.Resource, 
         Emphasize = true, 
         IncludeAllClaimsForUser = true, 
         Claims = new List<ScopeClaim> 
         { 
          new ScopeClaim(ClaimTypes.Name),  
          new ScopeClaim(ClaimTypes.Role) 
         } 
        } 
       }; 


public void CallApiUsingClientCredentials() 
       { 
        var tokenClient = new TokenClient("http://localhost:5000/connect/token", "mvc", "secret"); 
        var tokenResponse = await tokenClient.RequestClientCredentialsAsync("api1"); 

        var client = new HttpClient(); 
        client.SetBearerToken(tokenResponse.AccessToken); 
        var content = await client.GetStringAsync("http://localhost:5001/identity"); 

        var result = JArray.Parse(content).ToString(); 

       } 

[Authorize(Roles="admin)] 
      [HttpGet] 
      public IActionResult Get() 
        { 
         return new JsonResult(from c in User.Claims select new { c.Type, c.Value }); 
       } 

Trả lời

0

Trong WebForms bạn có thể thiết lập ủy quyền bằng web.config

<configuration> 
    <system.web> 
    <authorization> 
     <allow roles="domainname\Managers" /> 
     <deny users="*" /> 
    </authorization> 
    </system.web> 
</configuration> 

Từ answer on StackOverflow

Ngoài ra nhìn vào web.config trong ví dụ của IdentityServer3

<location path="About"> 
    <system.web> 
     <authorization> 
     <deny users="?" /> 
     </authorization> 
    </system.web> 
    </location> 
Các vấn đề liên quan