Getting an error "idtoken: invalid token, token must have three segments; found 2"

I am validating the idToken issued by Google, using this package “”. But I am getting the error " invalid token, token must have three segments; found 2 ". IdToken is in the right format. Please guide.

I don’t know anything about idtokens, but the code that produces that error looks to be here:

segments := strings.Split(idToken, ".")
	if len(segments) != 3 {
		return nil, fmt.Errorf("idtoken: invalid token, token must have three segments; found %d", len(segments))

Does the token have 2 “.” characters in it? Can you post a sample token with some or all of the alphanumeric characters obfuscated?

Token is in the right format. I have tested by hard-coding it in my code. Like I kept the token in one singe line. It is working fine. The moment the token takes the next line it is giving the error.
Technically I am using Goa web framework and testing from postman.
content-type: application/json

To explain it better i have taken the sample token from
case 1:
If the token is going to next line like in the below format, it is throwing error

If the token is in one single line, it is working fine.
Note here I have removed some token for understanding purpose, but in original the complete token stands in one line

I am thinking to use “minify” function. May be this should be work around. Please help me if you find a better solution.

I’m unable to reproduce this because I’m getting a build error. Here’s the main.go that I wrote to try this out:

package main

import (


func main() {
	_, err := idtoken.Validate(context.Background(), "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", "")
	fmt.Println("err:", err)

But when I try to run it, I get this error:

package command-line-arguments
        ..\..\\googleapis\google-api-go-client\idtoken\compute.go:15:2: use of internal package not allowed

Is there some other way you validate this jwt?

We need to use this package in import “

payload, err := idtoken.Validate(ctx, idToken, aud)

idToken and aud(i.e app clientId), need to pass to the above function.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.