Example #1
0
func waitForDeviceVerification(token string) (string, error) {
	req, err := http.NewRequest("GET", apiServer+"/Q", nil)
	if err != nil {
		log.Fatalf("Problem making verification request. Cannot verify. \n%v", err)
	}
	req.Header.Add("X-Line-Access", token)
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatalf("Error with response from verification request: %v\n", err)
	}
	jsonresp := make(map[string]interface{})
	dec := json.NewDecoder(resp.Body)
	err = dec.Decode(&jsonresp)
	if err != nil {
		log.Fatalf("Problem decoding json response during verification: %v", err)
	}
	result, ok := jsonresp["result"]
	if !ok {
		if errM, ok := jsonresp["errorMessage"]; !ok {
			log.Fatalf("Unrecognized JSON response during verification: %v", jsonresp)
		} else {
			log.Fatalf("Error during verification: %v", errM)
		}
	}
	resMap := result.(map[string]string)
	_, ok = resMap["authPhase"]
	if !ok {
		log.Printf("expected authPhase; respMap: %v\n", resMap)
	}
	verifier, ok := resMap["verifier"]
	if !ok {
		log.Printf("expected verifier; respMap: %v\n", resMap)
	}
	trans, err := thrift.NewTHttpPostClient(apiServer + "/api/v4/TalkService.do")
	if err != nil {
		return "", err
	}
	defer trans.Close()

	trans.(*thrift.THttpClient).SetHeader("X-Line-Application", "DESKTOPWIN\t3.2.1.83\tWINDOWS\t5.1.2600-XP-x64")
	trans.(*thrift.THttpClient).SetHeader("X-Line-Access", verifier)

	if err = trans.Open(); err != nil {
		return "", err
	}
	client := line.NewTalkServiceClientFactory(trans, thrift.NewTCompactProtocolFactory())
	lr, err := client.LoginWithVerifierForCertificate(verifier)
	if err != nil {
		return "", err
	}
	return lr.GetAuthToken(), nil
}
Example #2
-1
func NewStandardClient(path string) (*line.TalkServiceClient, error) {
	u, err := url.Parse(apiServer)
	if err != nil {
		return &line.TalkServiceClient{}, err
	}
	u.Path = path
	trans, err := thrift.NewTHttpPostClient(u.String())
	if err != nil {
		return &line.TalkServiceClient{}, err
	}

	trans.(*thrift.THttpClient).SetHeader("X-Line-Application", "DESKTOPWIN\t3.2.1.83\tWINDOWS\t5.1.2600-XP-x64")

	client := line.NewTalkServiceClientFactory(trans, thrift.NewTCompactProtocolFactory())
	return client, nil
}