feat: interactive auth method selection with API token validation
- Add GetToken() as unified auth entry point with method selection - Prompt [1] OAuth / [2] API token on first launch, save choice - Validate API tokens against /api/v1/users/self before saving - Check saved API token validity on reuse; fallback to re-prompt on failure - Add HTTP status check to GetCourseInfo and GetEnrolledCourses - Remove --api flag, auth method is now persistent and interactive
This commit is contained in:
@@ -17,19 +17,12 @@ 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)
|
||||
var accessToken string
|
||||
var err error
|
||||
if *apiToken {
|
||||
accessToken, err = authenticator.GetAPIToken()
|
||||
} else {
|
||||
accessToken, err = authenticator.GetAccessToken()
|
||||
}
|
||||
accessToken, err := authenticator.GetToken()
|
||||
if err != nil {
|
||||
fmt.Printf("Authentication failed: %v\n", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user