Verify Facebook access token
oidc is not supported.
Go :
import "github.com/go-resty/resty/v2"
type FacebookTokenResp struct {
Data struct {
AppId string `json:"app_id"`
Type string `json:"type"`
Application string `json:"application"`
DataAccessExpiresAt int64 `json:"data_access_expires_at"`
ExpiresAt int64 `json:"expires_at"`
IsValid bool `json:"is_valid"`
IssuedAt int64 `json:"issued_at"`
UserId string `json:"user_id"`
MetaData struct {
AuthType string `json:"auth_type"`
Sso string `json:"sso"`
} `json:"metadata"`
Scopes []string `json:"scopes"`
} `json:"data"`
}
func verifyFacebookAccessToken(token string) bool {
clientId := ""
clientSecret := ""
appAccessToken := clientId + "|" + clientSecret
client := resty.New()
resp, err := client.R().
SetHeader("Accept", "application/json").
Get(fmt.Sprintf("https://graph.facebook.com/debug_token?input_token=%s&access_token=%s",
token,
appAccessToken))
if err != nil {
logging.Error("facebook: %s", err)
return false
}
facebookTokenResp := FacebookTokenResp{}
if err := json.Unmarshal(resp.Body(), &facebookTokenResp); err != nil {
logging.Error("json Unmarshal: %s", err)
return false
}
if !facebookTokenResp.Data.IsValid {
logging.Error("facebook isValid false")
return false
}
return true
}
Last updated