How Gmail API refreshes token?

61 views
Skip to first unread message

Grigorii Tkachuk

unread,
Sep 9, 2019, 12:59:49 AM9/9/19
to golang-nuts
I'm looking into this example https://github.com/gsuitedevs/go-samples/blob/master/gmail/quickstart/quickstart.go and I do not understand why it refreshes "token.json". On line 45 we are passing token itself but not a path to token file. I went thru a documentation and source code but I do not understand how it works. My goal to put service which interacts with gmail api inside k8s cluster and I'm searching a way to pass and store token using k8s secrets but in the first of all I want to understand how it works with files. 

burak serdar

unread,
Sep 9, 2019, 9:58:34 AM9/9/19
to Grigorii Tkachuk, golang-nuts
On Sun, Sep 8, 2019 at 10:59 PM Grigorii Tkachuk <tkac...@gmail.com> wrote:
>
> I'm looking into this example https://github.com/gsuitedevs/go-samples/blob/master/gmail/quickstart/quickstart.go and I do not understand why it refreshes "token.json". On line 45 we are passing token itself but not a path to token file. I went thru a documentation and source code but I do not understand how it works. My goal to put service which interacts with gmail api inside k8s cluster and I'm searching a way to pass and store token using k8s secrets but in the first of all I want to understand how it works with files.

It looks like it is using oauth2. It helps if you understand how
oauth2 works. In short, it is authenticating with the server using
some credentials from a file, and then using an already existing token
if there is one (token.json), or requesting a new token using an
authorization code if there isn't one, and storing it in token,json.
All interactions with the server will use that token after that.

The token (probably a jwt) stores the scopes you can access, and it
usually has an expiration date. When the token expires, you have to
reauthenticate and get a new token, or use a refresh token if there is
one. So in your case, I suggest you figure out if those tokens expire.
If they do, then you'd have to manually get tokens and update your k8s
secrets and bounce your pods to update them when you get new tokens.
An alternative would be to store the tokens in a database so they can
be shared between pods without a need for an update and bounce.

>
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d3d55244-5d75-464a-86af-8ce5a4eaa09b%40googlegroups.com.

Dimas Prawira

unread,
Sep 9, 2019, 11:09:53 AM9/9/19
to Grigorii Tkachuk, golang-nuts
I never use Gmail API, maybe I will do dumb solution,  running the sample in local and see how it is going on.

On Mon, Sep 9, 2019 at 11:59 AM Grigorii Tkachuk <tkac...@gmail.com> wrote:
I'm looking into this example https://github.com/gsuitedevs/go-samples/blob/master/gmail/quickstart/quickstart.go and I do not understand why it refreshes "token.json". On line 45 we are passing token itself but not a path to token file. I went thru a documentation and source code but I do not understand how it works. My goal to put service which interacts with gmail api inside k8s cluster and I'm searching a way to pass and store token using k8s secrets but in the first of all I want to understand how it works with files. 

--
Reply all
Reply to author
Forward
0 new messages