Code Monkey home page Code Monkey logo

Comments (7)

pekspro avatar pekspro commented on August 27, 2024 1

I have been able to update this project to .NET Core 2.1 so it is possible. If I compare my update with the 2.0 version I see one difference in StartUp.ConfigureServices. The 2.0 code looks like this:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication(sharedOptions =>
        {
            sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
        })
        .AddAzureAd(options => Configuration.Bind("AzureAd", options))
        .AddCookie();

        services.AddMvc();

        // This sample uses an in-memory cache for tokens and subscriptions. Production apps will typically use some method of persistent storage.
        services.AddMemoryCache();
        services.AddSession();

        // Add application services.
        //services.AddSingleton<IConfiguration>(Configuration);
        services.AddSingleton<IGraphAuthProvider, GraphAuthProvider>();
        services.AddTransient<IGraphSdkHelper, GraphSdkHelper>();
    }

And my updated version to 2.1 looks like this:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication(sharedOptions =>
        {
            sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
        })
        .AddAzureAd(options => Configuration.Bind("AzureAd", options))
        .AddCookie();

        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        //services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
        //    .AddAzureAD(options => Configuration.Bind("AzureAd", options));


        services.AddMvc(options =>
        {
            var policy = new AuthorizationPolicyBuilder()
                .RequireAuthenticatedUser()
                .Build();
            options.Filters.Add(new AuthorizeFilter(policy));
        })
        .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);


        // This sample uses an in-memory cache for tokens and subscriptions. Production apps will typically use some method of persistent storage.
        services.AddMemoryCache();
        services.AddSession();

        // Add application services.
        //services.AddSingleton<IConfiguration>(Configuration);
        services.AddSingleton<IGraphAuthProvider, GraphAuthProvider>();
        services.AddTransient<IGraphSdkHelper, GraphSdkHelper>();
    }

Maybe that helps a bit. Otherwise I see no significant changes to the code.

from aspnetcore-connect-sample.

 avatar commented on August 27, 2024 1

Worked for me, thanks @pekspro !

from aspnetcore-connect-sample.

 avatar commented on August 27, 2024

Also guidance on how to trap and log the errors is ideal. (how would I handle tracing this in production?)

from aspnetcore-connect-sample.

mark-szabo avatar mark-szabo commented on August 27, 2024

Hi @ZeroPKI
It would be great to have the logs from the app. On localhost you can check the logs in VisualStudio. In a published app on Azure you can use the Diagnostic logs feature of Web Apps. To check what the tokens are doing between login.microsoftonline.com and your app, you can use fiddler for example.

from aspnetcore-connect-sample.

mark-szabo avatar mark-szabo commented on August 27, 2024

@pekspro pull requests are welcomed! 😉

from aspnetcore-connect-sample.

pekspro avatar pekspro commented on August 27, 2024

@mark-szabo, OK :-) I created PR #22

from aspnetcore-connect-sample.

mark-szabo avatar mark-szabo commented on August 27, 2024

Merged #22

from aspnetcore-connect-sample.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.