Hi Edwinn,
You can remove the code from the startup and build it again inside a controller.
You will need:
Send a get:
https://famonline.test.instructure.com/login/oauth2/auth?client_id=ur_client_id_canvas_app&response_...
On your redirect, u can create a function to receive the code FunctionName(string code)
Getting the code, u will send a post:
var response = await client.PostAsync("https://xxxxx.test.instructure.com/login/oauth2/token?grant_type=authorization_code&client_id=xxxxx&client_secret=xxxxx&redirect_uri=https://localhost:xxxx/Home/GetCode&code=" + _code, null);
With the response, you will get your access_token, the refresh_token and a few other variables
If you dont want the user to create a new token every time, you will need to implement the lti flow and get the oauth variable that canvas send when you click on the app menu (check this: .NET LTI Project - Part 2 - Launch Request )
with that, you will get the user_id from canvas that are starting your app, u can check if that id has a access_token/refresh_token stored on ur Bd, and with that, authorize the user or not.
After that, ur able to run any api call using the access_token that is stored (if the app have all the scoped u want)
Hope it helps!