77 "time"
88
99 "code.cloudfoundry.org/cli/v9/actor/sharedaction"
10- "github.com/SermoDigital/jose/jws "
10+ utiljwt "code.cloudfoundry.org/cli/v9/util/jwt "
1111)
1212
1313func (actor Actor ) GetStreamingLogsForApplicationByNameAndSpace (appName string , spaceGUID string , client sharedaction.LogCacheClient ) (<- chan sharedaction.LogMessage , <- chan error , context.CancelFunc , Warnings , error ) {
@@ -92,17 +92,17 @@ func (actor Actor) refreshAccessTokenIfNecessary() (*time.Duration, error) {
9292 }
9393
9494 accessToken = strings .TrimPrefix (accessToken , "bearer " )
95- token , err := jws . ParseJWT ([] byte ( accessToken ) )
95+ claims , err := utiljwt . Parse ( accessToken )
9696 if err != nil {
9797 return nil , err
9898 }
9999
100100 var timeToRefresh time.Duration
101- expiration , ok := token . Claims (). Expiration ()
102- if ! ok {
101+ expiration , err := claims . GetExpirationTime ()
102+ if err != nil || expiration == nil {
103103 return nil , errors .New ("Failed to get an expiry time from the current access token" )
104104 }
105- expiresIn := time .Until (expiration )
105+ expiresIn := time .Until (expiration . Time )
106106 if expiresIn >= 2 * time .Minute {
107107 timeToRefresh = expiresIn - time .Minute
108108 } else {
@@ -115,14 +115,14 @@ func (actor Actor) tokenExpiryTime(accessToken string) (*time.Duration, error) {
115115 var expiresIn time.Duration
116116
117117 accessTokenString := strings .TrimPrefix (accessToken , "bearer " )
118- token , err := jws . ParseJWT ([] byte ( accessTokenString ) )
118+ claims , err := utiljwt . Parse ( accessTokenString )
119119 if err != nil {
120120 return nil , err
121121 }
122122
123- expiration , ok := token . Claims (). Expiration ()
124- if ok {
125- expiresIn = time .Until (expiration )
123+ expiration , err := claims . GetExpirationTime ()
124+ if err == nil && expiration != nil {
125+ expiresIn = time .Until (expiration . Time )
126126 }
127127 return & expiresIn , nil
128128}
0 commit comments