pocketbase_plugin_telegram_auth

package module
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 14 Imported by: 0

README

Coverage

Overview

This plugin implements Telegram WebApp Auth and Telegram Login Widget for the pocketbase

Requirements

Installation

go get github.com/iamelevich/pocketbase-plugin-telegram-auth

Autofill fields

  • name - string
  • first_name - string
  • last_name - string
  • telegram_username - string
  • telegram_id - string
  • language_code - string

Example

You can check examples in examples folder

package main

import (
	tgAuthPlugin "github.com/iamelevich/pocketbase-plugin-telegram-auth"
	"log"

	"github.com/pocketbase/pocketbase"
)

func main() {
	app := pocketbase.New()

	// Setup tg auth for users collection
	tgAuthPlugin.MustRegister(app, &tgAuthPlugin.Options{
		BotToken:      "YOUR_SUPER_SECRET_BOT_TOKEN", // Better to use ENV variable for that
		CollectionKey: "users",
	})

	if err := app.Start(); err != nil {
		log.Fatal(err)
	}
}

After that new route POST /api/collections/users/auth-with-telegram will be available.

Usage

Simple usage with js. You can check react example here

const pb = new PocketBase('http://127.0.0.1:8090');
pb.send('/api/collections/users/auth-with-telegram', {
    method: 'POST',
    body: {
        data: window.Telegram.WebApp.initData
    }
}).then(res => {
    pb.authStore.save(res.token, res.record);
});

Contributing

This pocketbase plugin is free and open source project licensed under the MIT License. You are free to do whatever you want with it, even offering it as a paid service.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	BotToken      string
	CollectionKey string
}

Options defines optional struct to customize the default plugin behavior.

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

func MustRegister

func MustRegister(app core.App, options *Options) *Plugin

func Register

func Register(app core.App, options *Options) (*Plugin, error)

func (*Plugin) AuthByTelegramData

func (p *Plugin) AuthByTelegramData(tgData forms.TelegramData) (*models.Record, *auth.AuthUser, error)

func (*Plugin) GetCollection

func (p *Plugin) GetCollection() (*models.Collection, error)

func (*Plugin) GetForm

func (p *Plugin) GetForm(optAuthRecord *models.Record) (*forms.RecordTelegramLogin, error)

func (*Plugin) Validate

func (p *Plugin) Validate() error

Directories

Path Synopsis
examples
base command
webapp-react command

Jump to

Keyboard shortcuts

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