Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions telegram/telegram.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package telegram

import "golang.org/x/oauth2"

var Endpoint = oauth2.Endpoint{
AuthURL: "https://oauth.telegram.org/auth",
}

func SetTelegramAuthStyle(botID string, originDomain string, redirectURL string) []oauth2.AuthCodeOption {
return []oauth2.AuthCodeOption{
oauth2.SetAuthURLParam("bot_id", botID),
oauth2.SetAuthURLParam("origin", originDomain),
oauth2.SetAuthURLParam("return_to", redirectURL),
oauth2.SetAuthURLParam("request_access", "write&embed=0"),
}
}
6 changes: 6 additions & 0 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package oauth2

import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -172,6 +173,11 @@ func tokenFromInternal(t *internal.Token) *Token {
// This token is then mapped from *internal.Token into an *oauth2.Token which is returned along
// with an error.
func retrieveToken(ctx context.Context, c *Config, v url.Values) (*Token, error) {

if c.Endpoint.TokenURL == "" {
return nil, errors.New("oauth2: no token endpoint")
}

tk, err := internal.RetrieveToken(ctx, c.ClientID, c.ClientSecret, c.Endpoint.TokenURL, v, internal.AuthStyle(c.Endpoint.AuthStyle), c.authStyleCache.Get())
if err != nil {
if rErr, ok := err.(*internal.RetrieveError); ok {
Expand Down