12

mam rozwiązanie asp.net który składa się zasp.net formularz internetowy klient z serwerem tożsamości 4

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

nie widzę żadnej próbki z serwerem tożsamości 4 oraz formularz internetowy klienta. Czy możesz zasugerować, w jaki sposób uwierzytelnić użytkownika formularza internetowego przy użyciu serwera tożsamości z tożsamością asp.net, a następnie zadzwonić do api z tokenem dostępu?

nie widzę serwera tożsamość 4 próbki z web form client lub sample

serwerze tożsamości 3 ma sample ale robi wszystko, co w startup

Kiedy widzę mvc client dla serwera tożsamości 4, ma wszystko ustawienia w metodzie konfiguracyjnej, a następnie wywołuje ją w następujący sposób: Jak zastosować atrybut Authorize w formularzu internetowym, aby przekierować mnie na serwer tożsamości 4 w celu zalogowania, a następnie po zalogowaniu, gdy wywołuję api w ten sposób:

Jak zmienić klienta dla formularza internetowego?

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 }); 
       } 

Odpowiedz

0

W WebForms można skonfigurować autoryzację w web.config

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

Z answer on StackOverflow

spojrzeć także na web.config w przykładzie IdentityServer3

<location path="About"> 
    <system.web> 
     <authorization> 
     <deny users="?" /> 
     </authorization> 
    </system.web> 
    </location> 
Powiązane problemy