Example #1
0
func login(username string, password string, authChan chan Auth.AuthStageResult, bot *Auth.EvernoteAuthBot) {

    go bot.Login(username, password, authChan)

    // we use the select syntax 
    select {
        case result := <-authChan:
            log.Print("login received message")
            if result.Error != nil {
                handleErrors(result.Error, result.ErrorAssocObject)
            } else {
                // 2fa?
                elements := result.Elements
                log.Printf("login done: %v\n", elements)
                is2FA := result.Elements["is2FA"]
                if v, ok := is2FA.(bool); ok {
                    if v {
                        twoFACode := getUserAuthCode()
                        handle2FA(twoFACode, authChan, bot)
                    } else {
                        log.Println("No 2FA")
                        allowAccess(authChan, bot)
                    }
                }
            }
    }
}
Example #2
0
func handle2FA(authCode string, authChan chan Auth.AuthStageResult, bot *Auth.EvernoteAuthBot) {

    log.Print("getting 2fa")
    go bot.HandleTwoFactor(authCode, authChan)

    select {
        case result := <-authChan:
            if result.Error != nil {
                handleErrors(result.Error, result.ErrorAssocObject)
            } else {
                // Pass 2FA, go to get access
                allowAccess(authChan, bot)
            }
    }
}
Example #3
0
func getTmpToken(authChan chan Auth.AuthStageResult, bot *Auth.EvernoteAuthBot) {
    go bot.GetTmpOauthToken(authChan)

    // wait for result
    result := <-authChan

    if result.Error != nil {
        handleErrors(result.Error, result.ErrorAssocObject)
    } else {
        // proceed to login
        username, password := getLoginCredentials()
        login(username, password, authChan, bot)
    }

}
Example #4
0
func getOauthToken(verifier string, authChan chan Auth.AuthStageResult, bot *Auth.EvernoteAuthBot) {
    go bot.GetOauthToken(bot.TempOauthToken(), verifier, authChan)

    select {
        case result:=<-authChan:
            if result.Error != nil {
                handleErrors(result.Error, result.ErrorAssocObject)
            } else {
                switch v:=result.Elements["oauthToken"].(type) {
                    case string:
                        log.Printf("Got the token! %v", v)
                    default:
                        log.Fatal("Huge error, no token")
                }
            }
    }
}
Example #5
0
func allowAccess(authChan chan Auth.AuthStageResult, bot *Auth.EvernoteAuthBot) {

    log.Print("getting auth token")
    go bot.AllowAccess(bot.TempOauthToken(), authChan)

    select {
        case result:= <-authChan:
            if result.Error != nil {
                handleErrors(result.Error, result.ErrorAssocObject)
            } else {
                switch v := result.Elements["verifier"].(type) {
                    case string:
                        log.Print("getting oauth token")
                        getOauthToken(v, authChan, bot)
                    default:
                        log.Fatal("No verifier returned")
                }
            }
    }
}