vkapps

package
v2.0.0-...-dff137e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2023 License: MIT Imports: 9 Imported by: 0

README

VK Mini Apps

PkgGoDev VK

VK Mini Apps — это платформа встраиваемых кроссплатформенных приложений ВКонтакте. В данном модуле собраны инструменты для Backend части приложения.

Проверка параметров запуска

При запуске сервиса на указанный в управлении приложением URL передаются дополнительные параметры, содержащие в себе данные о пользователе и об источнике запуска.

Проверка подписи в ссылке:

link := "https://example.com/?vk_user_id=494075&vk_app_id=6736218&vk_is_app_user=1&vk_are_notifications_enabled=1&vk_language=ru&vk_access_token_settings=&vk_platform=android&sign=htQFduJpLxz7ribXRZpDFUH-XEUhC9rBPTJkjUFEkRA"

v, _ := vkapps.ParamsVerify(link, "wvl68m4dR1UpLrVRli")

fmt.Println(v)

// Output:
// true
VerifyMiddleware(next http.Handler) http.Handler

VerifyMiddleware это промежуточный http обработчик, который проверяет подпись. Если подпись верна - вызывает следующий обработчик, иначе возвращает 403 ошибку.

pv := vkapps.NewParamsVerification(clientSecret)

// Перед следующие обработчиками будет проверяться подпись
http.HandleFunc("/api/user/", pv.VerifyMiddleware(UserHandler))
http.HandleFunc("/api/user/details", pv.VerifyMiddleware(UserDetailsHandler))

Пример использования в mux

pv := vkapps.NewParamsVerification(clientSecret)

r := mux.NewRouter()

// Перед следующие обработчиками будет проверяться подпись
s := r.PathPrefix("/api").Subrouter()
s.HandleFunc("/user/", UserHandler) // /api/user/
s.HandleFunc("/user/details", UserDetailsHandler) // /api/user/details
s.Use(pv.VerifyMiddleware)

// Проверки подписи не будет
r.HandleFunc("/", PublicHandler)

Documentation

Overview

Package vkapps for VK Mini Apps.

See more https://vk.com/dev/vk_apps_docs

Index

Examples

Constants

View Source
const (
	ClientOk = "ok"
)

Possible values.

Variables

This section is empty.

Functions

func ParamsVerify

func ParamsVerify(link, clientSecret string) (bool, error)

ParamsVerify verifies the signature in link using client secret.

Example
package main

import (
	"fmt"

	"github.com/error-ident/vksdk/v2/vkapps"
)

func main() {
	link := "https://example.com/?vk_user_id=494075&vk_app_id=6736218&vk_is_app_user=1&vk_are_notifications_enabled=1&vk_language=ru&vk_access_token_settings=&vk_platform=android&sign=htQFduJpLxz7ribXRZpDFUH-XEUhC9rBPTJkjUFEkRA"

	v, _ := vkapps.ParamsVerify(link, "wvl68m4dR1UpLrVRli")

	fmt.Println(v)

}
Output:

true

Types

type Client

type Client string

Client from which the service is launched.

type Params

type Params struct {
	VkUserID                  int      `schema:"vk_user_id"`
	VkAppID                   int      `schema:"vk_app_id"`
	VkIsAppUser               bool     `schema:"vk_is_app_user"`
	VkAreNotificationsEnabled bool     `schema:"vk_are_notifications_enabled"`
	VkIsFavorite              bool     `schema:"vk_is_favorite"`
	VkLanguage                string   `schema:"vk_language"`
	VkRef                     Referral `schema:"vk_ref"`
	VkAccessTokenSettings     string   `schema:"vk_access_token_settings"`
	VkGroupID                 int      `schema:"vk_group_id"`
	VkViewerGroupRole         Role     `schema:"vk_viewer_group_role"`
	VkPlatform                Platform `schema:"vk_platform"`
	VkTs                      string   `schema:"vk_ts"`
	VkClient                  Client   `schema:"vk_client"`
	Sign                      string   `schema:"sign"`
}

Params service launch parameters.

func NewParams

func NewParams(u *url.URL) (*Params, error)

NewParams returns Params from url.

type ParamsVerification

type ParamsVerification struct {
	ClientSecret string
}

ParamsVerification represents verification struct.

Example
package main

import (
	"fmt"
	"net/url"

	"github.com/error-ident/vksdk/v2/vkapps"
)

func main() {
	link := "https://example.com/?vk_user_id=494075&vk_app_id=6736218&vk_is_app_user=1&vk_are_notifications_enabled=1&vk_language=ru&vk_access_token_settings=&vk_platform=android&sign=htQFduJpLxz7ribXRZpDFUH-XEUhC9rBPTJkjUFEkRA"

	pv := vkapps.NewParamsVerification("wvl68m4dR1UpLrVRli") // Client secret

	u, _ := url.Parse(link)

	v, _ := pv.Verify(u)

	fmt.Println(v)

}
Output:

true

func NewParamsVerification

func NewParamsVerification(clientSecret string) *ParamsVerification

NewParamsVerification return *ParamsVerification.

func (*ParamsVerification) Sign

func (pv *ParamsVerification) Sign(p []byte) string

Sign return signature in base64.

func (*ParamsVerification) Verify

func (pv *ParamsVerification) Verify(u *url.URL) (bool, error)

Verify verifies the signature in URL.

func (*ParamsVerification) VerifyMiddleware

func (pv *ParamsVerification) VerifyMiddleware(next http.Handler) http.Handler

VerifyMiddleware func.

type Platform

type Platform string

Platform from which the service is launched.

const (
	MobileAndroid          Platform = "mobile_android"
	MobileIPhone           Platform = "mobile_iphone"
	MobileWeb              Platform = "mobile_web"
	DesktopWeb             Platform = "desktop_web"
	MobileAndroidMessenger Platform = "mobile_android_messenger"
	MobileIPhoneMessenger  Platform = "mobile_iphone_messenger"
)

Possible values.

type Referral

type Referral string

Referral source.

const (
	Catalog               Referral = "catalog"
	CatalogRecent         Referral = "catalog_recent"
	CatalogFavourites     Referral = "catalog_favourites"
	CatalogRecommendation Referral = "catalog_recommendation"
	CatalogTopDau         Referral = "catalog_top_dau"
	CatalogEntertainment  Referral = "catalog_entertainment"
	CatalogCommunication  Referral = "catalog_communication"
	CatalogTools          Referral = "catalog_tools"
	CatalogShopping       Referral = "catalog_shopping"
	CatalogEvents         Referral = "catalog_events"
	CatalogEducation      Referral = "catalog_education"
	CatalogPayments       Referral = "catalog_payments"
	CatalogFinance        Referral = "catalog_finance"
	CatalogFood           Referral = "catalog_food"
	CatalogHealth         Referral = "catalog_health"
	CatalogTravel         Referral = "catalog_travel"
	CatalogTaxi           Referral = "catalog_taxi"
	CatalogJobs           Referral = "catalog_jobs"
	CatalogRealty         Referral = "catalog_realty"
	CatalogBusiness       Referral = "catalog_business"
	CatalogLifestyle      Referral = "catalog_lifestyle"
	CatalogAdmin          Referral = "catalog_admin"
	BoardTopicAll         Referral = "board_topic_all"
	BoardTopicView        Referral = "board_topic_view"
	Feed                  Referral = "feed"
	FeedPost              Referral = "feed_post"
	FeedComments          Referral = "feed_comments"
	FeaturingDiscover     Referral = "featuring_discover"
	FeaturingMenu         Referral = "featuring_menu"
	FeaturingNew          Referral = "featuring_new"
	Fave                  Referral = "fave"
	FaveLinks             Referral = "fave_links"
	FavePosts             Referral = "fave_posts"
	Group                 Referral = "group"
	GroupMenu             Referral = "group_menu"
	GroupMessages         Referral = "group_messages"
	GroupAddresses        Referral = "group_addresses"
	SnippetPost           Referral = "snippet_post"
	SnippetIm             Referral = "snippet_im"
	Clips                 Referral = "clips"
	CommentsListClip      Referral = "comments_list_clip"
	Im                    Referral = "im"
	ImChat                Referral = "im_chat"
	Notifications         Referral = "notifications"
	NotificationsGrouped  Referral = "notifications_grouped"
	NotificationsAuto     Referral = "notifications_auto"
	SuperApp              Referral = "super_app"
	HomeScreen            Referral = "home_screen"
	Menu                  Referral = "menu"
	SnippedPost           Referral = "snipped_post"
	Story                 Referral = "story"
	StoryReply            Referral = "story_reply"
	StoryViewer           Referral = "story_viewer"
	Profile               Referral = "profile"
	ArticleRead           Referral = "article_read"
	MusicPlaylist         Referral = "music_playlist"
	VideoCarousel         Referral = "video_carousel"
	PhotoBrowser          Referral = "photo_browser"
	ShoppingCenter        Referral = "shopping_center"
	MarketItem            Referral = "market_item"
	LeftNav               Referral = "left_nav"
	QuickSearch           Referral = "quick_search"
	Widget                Referral = "widget"
	Other                 Referral = "other"
	Showcase              Referral = "showcase"
)

Possible values.

func (Referral) Catalog

func (r Referral) Catalog() (categoryName string)

Catalog transition from the catalog. Return empty string if not Catalog.

func (Referral) Story

func (r Referral) Story() (userID int, params string)

Story transition from the story sticker. Return empty string if not Story.

type Role

type Role string

Role in the community from which the application is launched.

const (
	RoleNone   Role = "none"
	RoleMember Role = "member"
	RoleModer  Role = "moder"
	RoleEditor Role = "editor"
	RoleAdmin  Role = "admin"
)

Possible values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL