Documentation ¶
Index ¶
- Constants
- func RotateAccessToken(ctx context.Context, refresher TokenRefresher, revoker TokenRevoker, ...) error
- type Client
- func (c *Client) GenerateAccessToken(ctx context.Context, params GenerateAccessTokenParams) (*GenerateAccessTokenResponse, error)
- func (c *Client) InstallApp(ctx context.Context, params InstallAppParams) error
- func (c *Client) RefreshAccessToken(ctx context.Context, params RefreshAccessTokenParams) (*RefreshAccessTokenResponse, error)
- func (c *Client) RevokeAccessToken(ctx context.Context, params RevokeAccessTokenParams) (*RevokeAccessTokenResponse, error)
- type GenerateAccessTokenParams
- type GenerateAccessTokenResponse
- type InstallAppParams
- type RefreshAccessTokenParams
- type RefreshAccessTokenResponse
- type RevokeAccessTokenParams
- type RevokeAccessTokenResponse
- type SuccessResponse
- type TokenRefresher
- type TokenRevoker
- type TokenRotator
- type TokenRotatorFunc
- type TokenStore
- type TwoStepVerificationClient
- type TwoStepVerificationRequest
Constants ¶
const ( TokenScopeAdsManagement = "ads_management" TokenScopeAdsRead = "ads_read" TokenScopeAttributionRead = "attribution_read" TokenScopeBusinessManagement = "business_management" TokenScopeCatalogManagement = "catalog_management" TokenScopeCommerceAccountManageOrders = "commerce_account_manage_orders" TokenScopeCommerceAccountReadOrders = "commerce_account_read_orders" TokenScopeCommerceAccountReadSettings = "commerce_account_read_settings" TokenScopeInstagramBasic = "instagram_basic" //nolint:gosec TokenScopeInstagramBrandedContentAdsBrand = "instagram_branded_content_ads_brand" TokenScopeInstagramBrandedContentBrand = "instagram_branded_content_brand" TokenScopeInstagramContentPublish = "instagram_content_publish" //nolint:gosec TokenScopeInstagramManageComments = "instagram_manage_comments" TokenScopeInstagramManageInsights = "instagram_manage_insights" TokenScopeInstagramManageMessages = "instagram_manage_messages" TokenScopeInstagramShoppingTagProducts = "instagram_shopping_tag_products" //nolint:gosec TokenScopeLeadsRetrieval = "leads_retrieval" TokenScopePageEvents = "page_events" TokenScopePagesManageAds = "pages_manage_ads" TokenScopePagesManageCta = "pages_manage_cta" //nolint:gosec TokenScopePagesManageEngagement = "pages_manage_engagement" TokenScopePagesManageInstantArticles = "pages_manage_instant_articles" TokenScopePagesManageMetadata = "pages_manage_metadata" TokenScopePagesManagePosts = "pages_manage_posts" TokenScopePagesMessaging = "pages_messaging" TokenScopePagesReadEngagement = "pages_read_engagement" //nolint:gosec TokenScopePagesReadUserContent = "pages_read_user_content" //nolint:gosec TokenScopePagesShowList = "pages_show_list" TokenScopePrivateComputationAccess = "private_computation_access" TokenScopePublishVideo = "publish_video" TokenScopeReadAudienceNetworkInsights = "read_audience_network_insights" TokenScopeReadInsights = "read_insights" TokenScopeReadPageMailboxes = "read_page_mailboxes" //nolint:gosec TokenScopeWhatsappBusinessManagement = "whatsapp_business_management" TokenScopeWhatsappBusinessMessaging = "whatsapp_business_messaging" )
Variables ¶
This section is empty.
Functions ¶
func RotateAccessToken ¶
func RotateAccessToken( ctx context.Context, refresher TokenRefresher, revoker TokenRevoker, store TokenStore, ) error
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) GenerateAccessToken ¶
func (c *Client) GenerateAccessToken(ctx context.Context, params GenerateAccessTokenParams, ) (*GenerateAccessTokenResponse, error)
GenerateAccessToken generates a persistent access token for a system user. The system user must have installed the app beforehand. The generated access token is needed to make API calls on behalf of the system user.
Params: - ctx: The request context. - params: A struct containing:
- AccessToken: The access token of the user generating the new token.
- AppID: The ID of the app being used for token generation.
- SystemUserID: The ID of the system user generating the token.
- BaseURL: The base URL of the API.
- APIVersion: The version of the API being called.
- AppSecret: The app secret for generating the app secret proof.
- Scopes: The scopes (permissions) required for the new access token.
- SetTokenExpiresIn60: Boolean flag to set the token expiration to 60 days.
Returns: - *GenerateAccessTokenResponse: Contains the newly generated access token. - error: Any error encountered during the token generation process.
func (*Client) InstallApp ¶
func (c *Client) InstallApp(ctx context.Context, params InstallAppParams) error
InstallApp installs an app for a system user or an admin system user, allowing the app to make API calls on behalf of the user. Both the app and the system user should belong to the same Business Manager. Apps must have Ads Management API standard access or higher to be installed.
Params: - ctx: The request context. - params: A struct containing:
- AccessToken: The access token of an admin user, admin system user, or another system user.
- AppID: The ID of the app being installed.
- BaseURL: The base URL of the API.
- APIVersion: The version of the API being called.
- SystemUserID: The ID of the system user on whose behalf the app is installed.
Returns: - error: Any error encountered during the installation process.
func (*Client) RefreshAccessToken ¶
func (c *Client) RefreshAccessToken(ctx context.Context, params RefreshAccessTokenParams, ) (*RefreshAccessTokenResponse, error)
RefreshAccessToken sends a request to refresh an expiring system user access token.
func (*Client) RevokeAccessToken ¶
func (c *Client) RevokeAccessToken(ctx context.Context, params RevokeAccessTokenParams, ) (*RevokeAccessTokenResponse, error)
type GenerateAccessTokenParams ¶
type GenerateAccessTokenParams struct { AccessToken string // The access token of the user generating the new access token. AppID string // The ID of the app for which the token is generated. SystemUserID string // The system user ID that is generating the token. AppSecret string // The app secret associated with the app. Scopes []string // A list of permissions (scopes) to be granted to the new token. SetTokenExpiresIn60 bool // If true, sets the token to expire in 60 days. }
GenerateAccessTokenParams contains the parameters required to generate a persistent access token.
type GenerateAccessTokenResponse ¶
type GenerateAccessTokenResponse struct {
AccessToken string `json:"access_token"` // The newly generated access token.
}
GenerateAccessTokenResponse represents the response from generating an access token.
type InstallAppParams ¶
type InstallAppParams struct { AccessToken string // The access token of an admin or system user who installs the app. AppID string // The ID of the app being installed. SystemUserID string // The ID of the system user for whom the app is being installed. }
InstallAppParams contains the parameters required to install an app for a system user.
type RefreshAccessTokenParams ¶
type RefreshAccessTokenParams struct { ClientID string ClientSecret string FbExchangeToken string // Current access token GraphAPIVersion string SetTokenExpiresIn60 bool // Set to true to refresh for another 60 days }
RefreshAccessTokenParams contains the parameters for refreshing an access token.
type RefreshAccessTokenResponse ¶
type RefreshAccessTokenResponse struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` ExpiresIn int `json:"expires_in"` }
RefreshAccessTokenResponse contains the response from the refresh token request.
type RevokeAccessTokenParams ¶
type RevokeAccessTokenParams struct { ClientID string ClientSecret string RevokeToken string // Access token to revoke AccessToken string // Access token to identify the caller GraphAPIVersion string }
RevokeAccessTokenParams contains the parameters for revoking an access token.
type RevokeAccessTokenResponse ¶
type RevokeAccessTokenResponse struct {
Success bool `json:"success"`
}
type SuccessResponse ¶ added in v0.0.7
type SuccessResponse struct {
Success bool `json:"success,omitempty"` // Indicates if the app installation was successful.
}
SuccessResponse represents the response for the InstallApp API call.
type TokenRefresher ¶
type TokenRefresher interface {
Refresh(ctx context.Context, currentToken string) (string, error) // Refreshes and returns the new token
}
TokenRefresher defines an interface to refresh and fetch a new token.
type TokenRevoker ¶
type TokenRevoker interface {
Revoke(ctx context.Context, oldToken string) error // Revokes the old token
}
TokenRevoker defines an interface to revoke a token.
type TokenRotator ¶
type TokenRotator interface {
RotateToken(ctx context.Context, refresher TokenRefresher, revoker TokenRevoker, store TokenStore) error
}
type TokenRotatorFunc ¶
type TokenRotatorFunc func(ctx context.Context, refresher TokenRefresher, revoker TokenRevoker, store TokenStore) error
func (TokenRotatorFunc) RotateToken ¶
func (fn TokenRotatorFunc) RotateToken(ctx context.Context, refresher TokenRefresher, revoker TokenRevoker, store TokenStore, ) error
type TokenStore ¶
type TokenStore interface { Add(ctx context.Context, newToken string) error Get(ctx context.Context) (string, error) }
TokenStore defines an interface to store the new token.
type TwoStepVerificationClient ¶ added in v0.0.7
type TwoStepVerificationClient struct {
// contains filtered or unexported fields
}
func (*TwoStepVerificationClient) TwoStepVerification ¶ added in v0.0.7
func (c *TwoStepVerificationClient) TwoStepVerification(ctx context.Context, request *TwoStepVerificationRequest, ) (*SuccessResponse, error)
TwoStepVerification sends a request to set up two-step verification for a WhatsApp Business API phone number.