Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #12072
     shurman.cai
    Participant

    I got it work now. the key point is the response type: options.ResponseType = “id_token”; I have used “code” before.
    In “public void ConfigureServices(IServiceCollection services)” I add the following code

    services.AddAuthentication(
    options => options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);

    // Configure OIDC Options
    services.Configure<OpenIdConnectOptions>(options =>
    {
    options.AutomaticChallenge = true;
    options.AuthenticationScheme = “Openam”;
    options.MetadataAddress = “http://openam.contoso.com/openam/oauth2/.well-known/openid-configuration&#8221;;
    options.ClientId = Configuration[“openam:clientId”];
    options.ClientSecret = Configuration[“openam:clientSecret”];

    options.Scope.Add(“openid”);
    options.Scope.Add(“email”);
    options.Scope.Add(“profile”);
    options.RequireHttpsMetadata = false;
    // Set response type to code
    options.ResponseType = “id_token”;
    options.GetClaimsFromUserInfoEndpoint = true;

    options.Events = new OpenIdConnectEvents
    {
    OnRemoteFailure = context =>
    {
    context.Response.Redirect(“/AccessDenied>error=” + context.Failure.Message);
    return Task.FromResult(0);
    },
    OnTicketReceived = context =>
    {
    var identity = context.Principal.Identity as ClaimsIdentity;
    if (identity != null)
    {
    if (!context.Principal.HasClaim(c => c.Type == ClaimTypes.Name) &&
    identity.HasClaim(c => c.Type == “name”))
    identity.AddClaim(new Claim(ClaimTypes.Name, identity.FindFirst(“name”).Value));
    }
    return Task.FromResult(0);
    }
    };
    });

    In ” public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)”
    I added the following code

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
    AutomaticAuthenticate = true,
    AutomaticChallenge = true,
    LoginPath = new PathString(“/Account/Login”),
    LogoutPath = new PathString(“/Account/Logout”)
    });
    var options = app.ApplicationServices.GetRequiredService<IOptions<OpenIdConnectOptions>>();
    app.UseOpenIdConnectAuthentication(options.Value);

    • This reply was modified 6 years, 4 months ago by shurman.cai.
    #12056
     shurman.cai
    Participant

    Chrome does not work when the “cors” is enabled in OpenAm 13, the login page is hung up on “loading….”.

    • This reply was modified 6 years, 4 months ago by shurman.cai.
Viewing 2 posts - 1 through 2 (of 2 total)