CanvasOAuth 2.0.0

dotnet add package CanvasOAuth --version 2.0.0
NuGet\Install-Package CanvasOAuth -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CanvasOAuth" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CanvasOAuth --version 2.0.0
#r "nuget: CanvasOAuth, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CanvasOAuth as a Cake Addin
#addin nuget:?package=CanvasOAuth&version=2.0.0

// Install CanvasOAuth as a Cake Tool
#tool nuget:?package=CanvasOAuth&version=2.0.0

CanvasOAuth

This GitHub repo contains extension methods to add Canvas LMS OAuth to your application.

NuGet Package

A NuGet package was published to easily add this library to your projects.

You will find this package here.

Canvas LMS external login setup in ASP.NET Core

This tutorial shows you how to enable users to sign in with their Canvas account using an ASP.NET Core MVC application with Identity.

Create the Canvas OAuth 2.0 Client ID and secret

Store the Canvas client ID and secret

Add the CanvasOAuth NuGet package to the app.

Store sensitive settings such as the Canvas client ID and secret values with Secret Manager. For this sample, use the following steps:

  1. Initialize the project for secret storage per the instructions at Enable secret storage.

  2. Store the sensitive settings in the local secret store with the secret keys Authentication:Canvas:ClientId, Authentication:Canvas:ClientSecret, Authentication:Canvas:CanvasUrl:

    dotnet user-secrets set "Authentication:Canvas:ClientId" "<client-id>"
    dotnet user-secrets set "Authentication:Canvas:ClientSecret" "<client-secret>"
    dotnet user-secrets set "Authentication:Canvas:CanvasUrl" "<canvas-url>"
    

In environment variables, a : separator may not work on all platforms.

Configure Canvas authentication

Add the Authentication service to the Program:

builder.Services
    .AddAuthentication()
    .AddCanvas(o =>
    {
        o.ClientId = builder.Configuration["Authentication:Canvas:ClientId"];
        o.ClientSecret = builder.Configuration["Authentication:Canvas:ClientSecret"];

        o.AuthorizationEndpoint = $"{builder.Configuration["Authentication:Canvas:CanvasUrl"]}login/oauth2/auth";
        o.TokenEndpoint = $"{builder.Configuration["Authentication:Canvas:CanvasUrl"]}login/oauth2/token";
        o.UserInformationEndpoint = $"{builder.Configuration["Authentication:Canvas:CanvasUrl"]}api/v1/users/self";
    });

Sign in with Canvas

  • Run the app and select Log in. An option to sign in with Canvas appears.
  • Select the Canvas button, which redirects to Canvas for authentication.
  • After entering your Canvas credentials, you are redirected back to the web site.

Change the default callback URI

The URI segment /signin-canvas is set as the default callback of the Canvas authentication provider.

Troubleshooting

  • If the sign-in doesn't work and you aren't getting any errors, switch to development mode to make the issue easier to debug.
  • If Identity isn't configured by calling services.AddIdentity in ConfigureServices, attempting to authenticate results in ArgumentException: The 'SignInScheme' option must be provided. The project template used in this tutorial ensures Identity is configured.
  • If the site database has not been created by applying the initial migration, you get A database operation failed while processing the request error. Select Apply Migrations to create the database, and refresh the page to continue past the error.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 528 6/17/2022
1.0.1 390 5/24/2022
1.0.0 363 5/24/2022