43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
|
package extensions
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
"encoding/json"
|
|||
|
"net/http"
|
|||
|
"net/url"
|
|||
|
)
|
|||
|
|
|||
|
type GetExtensionSecretsResponse struct {
|
|||
|
// The list of shared secrets that the extension created.
|
|||
|
Data []ExtensionSecrets `json:"data"`
|
|||
|
}
|
|||
|
|
|||
|
// Gets an extension’s list of shared secrets.
|
|||
|
//
|
|||
|
// Requires a signed JSON Web Token (JWT) created by an EBS. For signing requirements,
|
|||
|
// see Signing the JWT: https://dev.twitch.tv/docs/extensions/building/#signing-the-jwt
|
|||
|
// The signed JWT must include the role, user_id, and exp fields
|
|||
|
// (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema).
|
|||
|
// The role field must be set to external.
|
|||
|
func (c *Extensions) GetExtensionSecrets(ctx context.Context, extensionID string) (*GetExtensionSecretsResponse, error) {
|
|||
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/jwt/secrets", RawQuery: "extension_id=" + extensionID})
|
|||
|
|
|||
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
res, err := c.client.Do(req)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
defer res.Body.Close()
|
|||
|
|
|||
|
var data GetExtensionSecretsResponse
|
|||
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
return &data, nil
|
|||
|
}
|