microsoft-authentication-library-for-dotnet icon indicating copy to clipboard operation
microsoft-authentication-library-for-dotnet copied to clipboard

ASP.NET Webforms Sample

Open hannespreishuber opened this issue 3 years ago • 4 comments

After days of trying nearly everything and reading - still no sucess

ASP.NET Webforms, MSGraph login startup

app.UseOpenIdConnectAuthentication(New OpenIdConnectAuthenticationOptions() With { .ClientId = clientId, .Authority = authority, .PostLogoutRedirectUri = postLogoutRedirectUri, .RedirectUri = "https://localhost:44399", .Notifications = New OpenIdConnectAuthenticationNotifications() With { .SecurityTokenValidated = Function(context) Dim name As String = context.AuthenticationTicket.Identity.FindFirst("preferred_username").Value context.AuthenticationTicket.Identity.AddClaim(New Claim(ClaimTypes.Name, name, String.Empty)) Return Task.FromResult(0) End Function, .AuthenticationFailed = Function(context) Return Task.FromResult(0) End Function } })

seems to be success. (user.identity.name)

account is null /nothing ClaimsPrincipal.Current. have user content in aspx page

`

    Dim app = ConfidentialClientApplicationBuilder.Create(ClientID) _
        .WithTenantId(tenantId) _
        .WithClientSecret(ClientSecret) _
           .WithAuthority(New Uri(authorityUri)) _
           .WithLegacyCacheCompatibility(False) _
    .WithRedirectUri(redirectUri).Build()
   app.AddInMemoryTokenCache()
    Dim result As AuthenticationResult
    '' Dim accounts = Await app.GetAccountsAsync() old???
    Dim Account = Await app.GetAccountAsync(ClaimsPrincipal.Current.GetMsalAccountId())

    Try

        result = Await app.AcquireTokenSilent(scopes, Account).ExecuteAsync().ConfigureAwait(False)

`

I am sure I miss some understanding

hannespreishuber avatar Jun 10 '22 20:06 hannespreishuber

@hannespreishuber : did you look at this sample: https://github.com/Azure-Samples/ms-identity-aspnet-webapp-openidconnect ?

jmprieur avatar Jun 13 '22 01:06 jmprieur

this is not Webforms. I know literally every sample

to complex- no dependency like [Authorize] to Webforms pattern

I am looking just for the 10 loc

hannespreishuber avatar Jun 13 '22 14:06 hannespreishuber

Which error do you get? Are you signing-in with a guest account? or an account in the directory?

jmprieur avatar Jun 13 '22 14:06 jmprieur

works with core and others. Azure AD - as I have written: account is null /nothing

hannespreishuber avatar Jun 13 '22 17:06 hannespreishuber