oauth2: handle token expiry for JWT

Change-Id: I84b4c282ef00e87d13a9b16fdcebd97ea5ed4f4e
Reviewed-on: https://go-review.googlesource.com/1650
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/jwt.go b/jwt.go
index 892ce0c..7c02e3d 100644
--- a/jwt.go
+++ b/jwt.go
@@ -131,7 +131,7 @@
 	token.AccessToken, _ = b["access_token"].(string)
 	token.TokenType, _ = b["token_type"].(string)
 	token.raw = b
-	if e, ok := b["expires_in"].(int); ok {
+	if e, ok := b["expires_in"].(float64); ok {
 		token.Expiry = time.Now().Add(time.Duration(e) * time.Second)
 	}
 	if idtoken, ok := b["id_token"].(string); ok {
diff --git a/jwt_test.go b/jwt_test.go
index 2fe371b..3cc5671 100644
--- a/jwt_test.go
+++ b/jwt_test.go
@@ -44,7 +44,8 @@
 		w.Write([]byte(`{
 			"access_token": "90d64460d14870c08c81352a05dedd3465940a7c",
 			"scope": "user",
-			"token_type": "bearer"
+			"token_type": "bearer",
+			"expires_in": 3600
 		}`))
 	}))
 	defer ts.Close()
@@ -59,13 +60,16 @@
 		t.Fatal(err)
 	}
 	if tok.Expired() {
-		t.Errorf("Token shouldn't be expired.")
+		t.Errorf("Token shouldn't be expired")
 	}
 	if tok.AccessToken != "90d64460d14870c08c81352a05dedd3465940a7c" {
-		t.Errorf("Unexpected access token, %#v.", tok.AccessToken)
+		t.Errorf("Unexpected access token, %#v", tok.AccessToken)
 	}
 	if tok.TokenType != "bearer" {
-		t.Errorf("Unexpected token type, %#v.", tok.TokenType)
+		t.Errorf("Unexpected token type, %#v", tok.TokenType)
+	}
+	if tok.Expiry.IsZero() {
+		t.Errorf("Unexpected token expiry, %#v", tok.Expiry)
 	}
 	scope := tok.Extra("scope")
 	if scope != "user" {