@@ -113,32 +113,6 @@ func (c *KeyFlow) GetToken() TokenResponseBody {
113113 return * c .token
114114}
115115
116- // SetToken can be used to set an access and refresh token manually in the client.
117- // The other fields in the token field are determined by inspecting the token or setting default values.
118- // Deprecated
119- func (c * KeyFlow ) SetToken (accessToken , refreshToken string ) error {
120- // We can safely use ParseUnverified because we are not authenticating the user,
121- // We are parsing the token just to get the expiration time claim
122- parsedAccessToken , _ , err := jwt .NewParser ().ParseUnverified (accessToken , & jwt.RegisteredClaims {})
123- if err != nil {
124- return fmt .Errorf ("parse access token to read expiration time: %w" , err )
125- }
126- exp , err := parsedAccessToken .Claims .GetExpirationTime ()
127- if err != nil {
128- return fmt .Errorf ("get expiration time from access token: %w" , err )
129- }
130-
131- c .tokenMutex .Lock ()
132- c .token = & TokenResponseBody {
133- AccessToken : accessToken ,
134- ExpiresIn : int (exp .Time .Unix ()),
135- Scope : "" ,
136- TokenType : "Bearer" ,
137- }
138- c .tokenMutex .Unlock ()
139- return nil
140- }
141-
142116func (c * KeyFlow ) Init (cfg * KeyFlowConfig ) error {
143117 // No concurrency at this point, so no mutex check needed
144118 c .token = & TokenResponseBody {}
@@ -171,6 +145,32 @@ func (c *KeyFlow) Init(cfg *KeyFlowConfig) error {
171145 return nil
172146}
173147
148+ // SetToken can be used to set an access and refresh token manually in the client.
149+ // The other fields in the token field are determined by inspecting the token or setting default values.
150+ // Deprecated
151+ func (c * KeyFlow ) SetToken (accessToken , refreshToken string ) error {
152+ // We can safely use ParseUnverified because we are not authenticating the user,
153+ // We are parsing the token just to get the expiration time claim
154+ parsedAccessToken , _ , err := jwt .NewParser ().ParseUnverified (accessToken , & jwt.RegisteredClaims {})
155+ if err != nil {
156+ return fmt .Errorf ("parse access token to read expiration time: %w" , err )
157+ }
158+ exp , err := parsedAccessToken .Claims .GetExpirationTime ()
159+ if err != nil {
160+ return fmt .Errorf ("get expiration time from access token: %w" , err )
161+ }
162+
163+ c .tokenMutex .Lock ()
164+ c .token = & TokenResponseBody {
165+ AccessToken : accessToken ,
166+ ExpiresIn : int (exp .Time .Unix ()),
167+ Scope : "" ,
168+ TokenType : "Bearer" ,
169+ }
170+ c .tokenMutex .Unlock ()
171+ return nil
172+ }
173+
174174// Roundtrip performs the request
175175func (c * KeyFlow ) RoundTrip (req * http.Request ) (* http.Response , error ) {
176176 if c .rt == nil {
0 commit comments