feat: add --api flag for Canvas API token authentication

- Add APIToken field to Credentials struct with omitempty JSON tag
- Implement GetAPIToken() method with persistent token storage
- Add SaveRefreshToken() helper to preserve API tokens during OAuth
- Implement --api CLI flag to use API token instead of OAuth
- Validate empty refresh tokens and skip refresh if invalid
- Update README with API token usage documentation
This commit is contained in:
2026-06-19 21:12:43 +02:00
parent 122d00c8f9
commit 666369714b
4 changed files with 74 additions and 9 deletions

View File

@@ -17,12 +17,19 @@ func main() {
videosOnly := flag.Bool("vo", false, "Videos only mode - download only Panopto videos to a single directory")
me := flag.Bool("me", false, "Download all enrolled courses")
moduleNumbers := flag.Bool("n", false, "Prefix modules with order numbers [1], [2], etc.")
apiToken := flag.Bool("api", false, "Use a manually generated Canvas API token instead of OAuth")
flag.Parse()
httpClient := &http.Client{}
authenticator := auth.NewAuthenticator(httpClient)
accessToken, err := authenticator.GetAccessToken()
var accessToken string
var err error
if *apiToken {
accessToken, err = authenticator.GetAPIToken()
} else {
accessToken, err = authenticator.GetAccessToken()
}
if err != nil {
fmt.Printf("Authentication failed: %v\n", err)
return