예제 #1
0
func ConnectPocket(res http.ResponseWriter, req *http.Request) {

	// Get the credentials Id
	var credId string

	if err := req.ParseForm(); err != nil {
		log.Fatal("Error parsing form")
	} else {
		credId := req.Form.Get("cid")
	}

	// Get the Pocket Request Token
	if redirectUri := os.Getenv(ENV_PO_SVC_CALLBACK); redirectUri != "" {
		token := pauth.GetPocketRequestToken(redirectUri)
		/*intCredId, err := strconv.Atoi(credId)*/
		/*if err != nil {*/
		creds, err := data.GetEverpocketCreds(map[string]string{"creds_id": credId})
		if err != nil {
			// no error, query success
			creds.PoRequestToken = token
			creds.Write()
		}
		/*}*/
	}
}
예제 #2
0
func EvernoteCallbackHandler(res http.ResponseWriter, req *http.Request) {

	if err := req.ParseForm(); err != nil {
		log.Println("Error parsing form: " + req.URL.Host + "/" + req.URL.Path)
	}

	token := req.Form.Get("oauth_token")
	verifier := req.Form.Get("oauth_verifier")

	log.Printf("Token = %v, verifier = %v", token, verifier)

	if token != "" && verifier != "" {
		// get the matching EverpocketCreds
		creds, _ := data.GetEverpocketCreds(map[string]string{
			"ev_temp_request_token": token,
		})

		log.Printf("Creds = %v", creds)
		if creds.EvTempRequestToken != token {
			log.Fatal("Error querying DB for token ", token, ".")
		}

		// use the verifier to exchange for the access token
		accessToken, accessSecret, addData, err := auth.GetEvernoteAccessToken(
			EVERNOTE_HOST,
			creds.EvTempRequestToken,
			creds.EvTempSecret,
			verifier,
			true,
		)

		if err != nil {
			log.Fatal("Error getting evernote access token: %v", err)
		}

		// TODO: once we have this set of info, we can write a goroutine to
		// write this to the database
		// and we just return OK so that we can do the next thing
		go func() {
			creds.EvAccessSecret = accessSecret
			creds.EvAccessToken = accessToken
			creds.EvAddData = addData
			err := creds.Write()
			if err != nil {
				log.Fatal("Failed to write evernote data: %v", err)
			}
		}()

		donePageUrl := fmt.Sprintf(DONEPAGE, "/connect_pocket?cid="+strconv.Itoa(creds.Id))

		res.Write([]byte(donePageUrl))
	}

}