Setting Up the Project

This guide provides step-by-step instructions for setting up your ASP.NET Core web application, "YourSite," to integrate with K12NET's APIs. By following these steps, you will prepare your project environment, configure necessary dependencies, and establish the foundation for implementing Single Sign-On (SSO) and API communication.

Prerequisites

Step 1: Create Your ASP.NET Core Project

  1. Open Visual Studio or Visual Studio Code.
  2. Create a new project and select "ASP.NET Core Web Application."
  3. Choose the appropriate project template (e.g., MVC or Razor Pages) based on your preference.
  4. Name your project "YourSite" and select a location for your project files.

Step 2: Configure Authentication

To integrate K12NET's SSO, configure the authentication services in your project.

  1. In the Program.cs file, add the following service :
            
    builder.Services.AddAuthentication(opt => opt.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
            		
            
  2. Program.cs content should be similar to below:
    
    using Microsoft.AspNetCore.Authentication.Cookies;
    
    namespace YourSite
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                var builder = WebApplication.CreateBuilder(args);
    
                builder.Services.AddRazorPages();
    
                builder.Services.AddAuthentication(opt => opt.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
    
                var app = builder.Build();
    
                if (!app.Environment.IsDevelopment())
                {
                    app.UseHsts();
                }
                app.UseStaticFiles();
    
                app.UseRouting();
    
                app.UseAuthentication();
    
                app.UseAuthorization();
    
                app.MapRazorPages();
    
                app.Run();
            }
        }
    }
    		
            

Step 3: Configure API Access Paremeters

Ensure your application has the K12NET Partner information.

  1. In the appsettings.json file, add the K12NETPartnerInfo element:
            
      "K12NETPartnerInfo": {
        "url": "https://api-test.k12net.com",
        "client_id": "YOUR_CLIENT_ID",
        "client_secret": "YOUR_CLIENT_SECRET",
        "redirect_uri": "https://localhost:5178/Signin-K12NET"
      }		
            
            
  2. Make sure you change the redirect_uri value according to your application's port.

Step 4: Build and Run

Conclusion

You have now successfully set up your ASP.NET Core project, "YourSite," with the foundational elements for integrating with K12NET's APIs and implementing SSO. The next steps involve diving deeper into the specific functionalities you wish to incorporate, such as user authentication, data retrieval, and more, which will be covered in subsequent guides.