Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronius committed Mar 30, 2023
2 parents 0c95480 + 271cf13 commit cb8f0c2
Show file tree
Hide file tree
Showing 153 changed files with 1,851 additions and 476 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
042f5311fcab71f9bd8ac33c1e25597799eb34d7
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ on:
pull_request:
branches:
- master
workflow_dispatch:

name: ci

jobs:
test:
strategy:
matrix:
go-version: [ 1.15.x, 1.16.x, 1.17.x, 1.18.x ]
go-version: [ 1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x ]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -21,7 +22,7 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Restore cache
uses: actions/cache@v2
with:
Expand All @@ -31,6 +32,6 @@ jobs:
${{ runner.os }}-go-
- name: Format
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
if: matrix.os != 'windows-latest'
if: matrix.os != 'windows-latest' && matrix.go-version == '1.19.x'
- name: Test
run: go test -race ./...
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ $ go get github.com/markbates/goth
* Intercom
* Kakao
* Lastfm
* Linkedin
* LINE
* Linkedin
* Mailru
* Meetup
* MicrosoftOnline
Expand All @@ -54,6 +54,7 @@ $ go get github.com/markbates/goth
* OneDrive
* OpenID Connect (auto discovery)
* Oura
* Patreon
* Paypal
* SalesForce
* Shopify
Expand All @@ -70,8 +71,8 @@ $ go get github.com/markbates/goth
* Typetalk
* Uber
* VK
* Wepay
* WeCom
* Wepay
* Xero
* Yahoo
* Yammer
Expand Down
141 changes: 76 additions & 65 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/markbates/goth/providers/okta"
"github.com/markbates/goth/providers/onedrive"
"github.com/markbates/goth/providers/openidConnect"
"github.com/markbates/goth/providers/patreon"
"github.com/markbates/goth/providers/paypal"
"github.com/markbates/goth/providers/salesforce"
"github.com/markbates/goth/providers/seatalk"
Expand All @@ -59,6 +60,7 @@ import (
"github.com/markbates/goth/providers/tiktok"
"github.com/markbates/goth/providers/twitch"
"github.com/markbates/goth/providers/twitter"
"github.com/markbates/goth/providers/twitterv2"
"github.com/markbates/goth/providers/typetalk"
"github.com/markbates/goth/providers/uber"
"github.com/markbates/goth/providers/vk"
Expand All @@ -73,6 +75,12 @@ import (

func main() {
goth.UseProviders(
// Use twitterv2 instead of twitter if you only have access to the Essential API Level
// the twitter provider uses a v1.1 API that is not available to the Essential Level
twitterv2.New(os.Getenv("TWITTER_KEY"), os.Getenv("TWITTER_SECRET"), "http://localhost:3000/auth/twitterv2/callback"),
// If you'd like to use authenticate instead of authorize in TwitterV2 provider, use this instead.
// twitterv2.NewAuthenticate(os.Getenv("TWITTER_KEY"), os.Getenv("TWITTER_SECRET"), "http://localhost:3000/auth/twitterv2/callback"),

twitter.New(os.Getenv("TWITTER_KEY"), os.Getenv("TWITTER_SECRET"), "http://localhost:3000/auth/twitter/callback"),
// If you'd like to use authenticate instead of authorize in Twitter provider, use this instead.
// twitter.NewAuthenticate(os.Getenv("TWITTER_KEY"), os.Getenv("TWITTER_SECRET"), "http://localhost:3000/auth/twitter/callback"),
Expand Down Expand Up @@ -105,15 +113,15 @@ func main() {
eveonline.New(os.Getenv("EVEONLINE_KEY"), os.Getenv("EVEONLINE_SECRET"), "http://localhost:3000/auth/eveonline/callback"),
kakao.New(os.Getenv("KAKAO_KEY"), os.Getenv("KAKAO_SECRET"), "http://localhost:3000/auth/kakao/callback"),

//Pointed localhost.com to http://localhost:3000/auth/yahoo/callback through proxy as yahoo
// Pointed localhost.com to http://localhost:3000/auth/yahoo/callback through proxy as yahoo
// does not allow to put custom ports in redirection uri
yahoo.New(os.Getenv("YAHOO_KEY"), os.Getenv("YAHOO_SECRET"), "http://localhost.com"),
typetalk.New(os.Getenv("TYPETALK_KEY"), os.Getenv("TYPETALK_SECRET"), "http://localhost:3000/auth/typetalk/callback", "my"),
slack.New(os.Getenv("SLACK_KEY"), os.Getenv("SLACK_SECRET"), "http://localhost:3000/auth/slack/callback"),
stripe.New(os.Getenv("STRIPE_KEY"), os.Getenv("STRIPE_SECRET"), "http://localhost:3000/auth/stripe/callback"),
wepay.New(os.Getenv("WEPAY_KEY"), os.Getenv("WEPAY_SECRET"), "http://localhost:3000/auth/wepay/callback", "view_user"),
//By default paypal production auth urls will be used, please set PAYPAL_ENV=sandbox as environment variable for testing
//in sandbox environment
// By default paypal production auth urls will be used, please set PAYPAL_ENV=sandbox as environment variable for testing
// in sandbox environment
paypal.New(os.Getenv("PAYPAL_KEY"), os.Getenv("PAYPAL_SECRET"), "http://localhost:3000/auth/paypal/callback"),
steam.New(os.Getenv("STEAM_KEY"), "http://localhost:3000/auth/steam/callback"),
heroku.New(os.Getenv("HEROKU_KEY"), os.Getenv("HEROKU_SECRET"), "http://localhost:3000/auth/heroku/callback"),
Expand All @@ -125,7 +133,7 @@ func main() {
discord.New(os.Getenv("DISCORD_KEY"), os.Getenv("DISCORD_SECRET"), "http://localhost:3000/auth/discord/callback", discord.ScopeIdentify, discord.ScopeEmail),
meetup.New(os.Getenv("MEETUP_KEY"), os.Getenv("MEETUP_SECRET"), "http://localhost:3000/auth/meetup/callback"),

//Auth0 allocates domain per customer, a domain must be provided for auth0 to work
// Auth0 allocates domain per customer, a domain must be provided for auth0 to work
auth0.New(os.Getenv("AUTH0_KEY"), os.Getenv("AUTH0_SECRET"), "http://localhost:3000/auth/auth0/callback", os.Getenv("AUTH0_DOMAIN")),
xero.New(os.Getenv("XERO_KEY"), os.Getenv("XERO_SECRET"), "http://localhost:3000/auth/xero/callback"),
vk.New(os.Getenv("VK_KEY"), os.Getenv("VK_SECRET"), "http://localhost:3000/auth/vk/callback"),
Expand All @@ -140,76 +148,79 @@ func main() {
mastodon.New(os.Getenv("MASTODON_KEY"), os.Getenv("MASTODON_SECRET"), "http://localhost:3000/auth/mastodon/callback", "read:accounts"),
wecom.New(os.Getenv("WECOM_CORP_ID"), os.Getenv("WECOM_SECRET"), os.Getenv("WECOM_AGENT_ID"), "http://localhost:3000/auth/wecom/callback"),
zoom.New(os.Getenv("ZOOM_KEY"), os.Getenv("ZOOM_SECRET"), "http://localhost:3000/auth/zoom/callback", "read:user"),
patreon.New(os.Getenv("PATREON_KEY"), os.Getenv("PATREON_SECRET"), "http://localhost:3000/auth/patreon/callback"),
)

// OpenID Connect is based on OpenID Connect Auto Discovery URL (https://openid.net/specs/openid-connect-discovery-1_0-17.html)
// because the OpenID Connect provider initialize it self in the New(), it can return an error which should be handled or ignored
// because the OpenID Connect provider initialize itself in the New(), it can return an error which should be handled or ignored
// ignore the error for now
openidConnect, _ := openidConnect.New(os.Getenv("OPENID_CONNECT_KEY"), os.Getenv("OPENID_CONNECT_SECRET"), "http://localhost:3000/auth/openid-connect/callback", os.Getenv("OPENID_CONNECT_DISCOVERY_URL"))
if openidConnect != nil {
goth.UseProviders(openidConnect)
}

m := make(map[string]string)
m["amazon"] = "Amazon"
m["bitbucket"] = "Bitbucket"
m["box"] = "Box"
m["dailymotion"] = "Dailymotion"
m["deezer"] = "Deezer"
m["digitalocean"] = "Digital Ocean"
m["discord"] = "Discord"
m["dropbox"] = "Dropbox"
m["eveonline"] = "Eve Online"
m["facebook"] = "Facebook"
m["fitbit"] = "Fitbit"
m["gitea"] = "Gitea"
m["github"] = "Github"
m["gitlab"] = "Gitlab"
m["google"] = "Google"
m["gplus"] = "Google Plus"
m["shopify"] = "Shopify"
m["soundcloud"] = "SoundCloud"
m["spotify"] = "Spotify"
m["steam"] = "Steam"
m["stripe"] = "Stripe"
m["tiktok"] = "TikTok"
m["twitch"] = "Twitch"
m["uber"] = "Uber"
m["wepay"] = "Wepay"
m["yahoo"] = "Yahoo"
m["yammer"] = "Yammer"
m["heroku"] = "Heroku"
m["instagram"] = "Instagram"
m["intercom"] = "Intercom"
m["kakao"] = "Kakao"
m["lastfm"] = "Last FM"
m["linkedin"] = "Linkedin"
m["line"] = "LINE"
m["onedrive"] = "Onedrive"
m["azuread"] = "Azure AD"
m["microsoftonline"] = "Microsoft Online"
m["battlenet"] = "Battlenet"
m["paypal"] = "Paypal"
m["twitter"] = "Twitter"
m["salesforce"] = "Salesforce"
m["typetalk"] = "Typetalk"
m["slack"] = "Slack"
m["meetup"] = "Meetup.com"
m["auth0"] = "Auth0"
m["openid-connect"] = "OpenID Connect"
m["xero"] = "Xero"
m["vk"] = "VK"
m["naver"] = "Naver"
m["yandex"] = "Yandex"
m["nextcloud"] = "NextCloud"
m["seatalk"] = "SeaTalk"
m["apple"] = "Apple"
m["strava"] = "Strava"
m["okta"] = "Okta"
m["mastodon"] = "Mastodon"
m["wecom"] = "WeCom"
m["zoom"] = "Zoom"

m := map[string]string{
"amazon": "Amazon",
"apple": "Apple",
"auth0": "Auth0",
"azuread": "Azure AD",
"battlenet": "Battle.net",
"bitbucket": "Bitbucket",
"box": "Box",
"dailymotion": "Dailymotion",
"deezer": "Deezer",
"digitalocean": "Digital Ocean",
"discord": "Discord",
"dropbox": "Dropbox",
"eveonline": "Eve Online",
"facebook": "Facebook",
"fitbit": "Fitbit",
"gitea": "Gitea",
"github": "Github",
"gitlab": "Gitlab",
"google": "Google",
"gplus": "Google Plus",
"heroku": "Heroku",
"instagram": "Instagram",
"intercom": "Intercom",
"kakao": "Kakao",
"lastfm": "Last FM",
"line": "LINE",
"linkedin": "LinkedIn",
"mastodon": "Mastodon",
"meetup": "Meetup.com",
"microsoftonline": "Microsoft Online",
"naver": "Naver",
"nextcloud": "NextCloud",
"okta": "Okta",
"onedrive": "Onedrive",
"openid-connect": "OpenID Connect",
"patreon": "Patreon",
"paypal": "Paypal",
"salesforce": "Salesforce",
"seatalk": "SeaTalk",
"shopify": "Shopify",
"slack": "Slack",
"soundcloud": "SoundCloud",
"spotify": "Spotify",
"steam": "Steam",
"strava": "Strava",
"stripe": "Stripe",
"tiktok": "TikTok",
"twitch": "Twitch",
"twitter": "Twitter",
"twitterv2": "Twitter",
"typetalk": "Typetalk",
"uber": "Uber",
"vk": "VK",
"wecom": "WeCom",
"wepay": "Wepay",
"xero": "Xero",
"yahoo": "Yahoo",
"yammer": "Yammer",
"yandex": "Yandex",
"zoom": "Zoom",
}
var keys []string
for k := range m {
keys = append(keys, k)
Expand Down
6 changes: 3 additions & 3 deletions gothic/gothic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Package gothic wraps common behaviour when using Goth. This makes it quick, and easy, to get up
and running with Goth. Of course, if you want complete control over how things flow, in regards
and running with Goth. Of course, if you want complete control over how things flow, in regard
to the authentication process, feel free and use Goth directly.
See https://github.com/markbates/goth/blob/master/examples/main.go to see this in action.
Expand Down Expand Up @@ -45,7 +45,7 @@ func init() {
key := []byte(os.Getenv("SESSION_SECRET"))
keySet = len(key) != 0

cookieStore := sessions.NewCookieStore([]byte(key))
cookieStore := sessions.NewCookieStore(key)
cookieStore.Options.HttpOnly = true
Store = cookieStore
defaultStore = Store
Expand Down Expand Up @@ -151,7 +151,7 @@ func GetAuthURL(res http.ResponseWriter, req *http.Request) (string, error) {

/*
CompleteUserAuth does what it says on the tin. It completes the authentication
process and fetches all of the basic information about the user from the provider.
process and fetches all the basic information about the user from the provider.
It expects to be able to get the name of the provider from the query parameters
as either "provider" or ":provider".
Expand Down
2 changes: 1 addition & 1 deletion gothic/gothic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func Test_CompleteUserAuthWithSessionDeducedProvider(t *testing.T) {
a := assert.New(t)

res := httptest.NewRecorder()
// Inteintionally omit a provider argument, force looking in session.
// Intentionally omit a provider argument, force looking in session.
req, err := http.NewRequest("GET", "/auth/callback", nil)
a.NoError(err)

Expand Down
4 changes: 2 additions & 2 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type Provider interface {
UnmarshalSession(string) (Session, error)
FetchUser(Session) (User, error)
Debug(bool)
RefreshToken(refreshToken string) (*oauth2.Token, error) //Get new access token based on the refresh token
RefreshTokenAvailable() bool //Refresh token is provided by auth provider or not
RefreshToken(refreshToken string) (*oauth2.Token, error) // Get new access token based on the refresh token
RefreshTokenAvailable() bool // Refresh token is provided by auth provider or not
}

const NoAuthUrlErrorMessage = "an AuthURL has not been set"
Expand Down
6 changes: 3 additions & 3 deletions providers/amazon/amazon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package amazon
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"

"fmt"
"github.com/markbates/goth"
"golang.org/x/oauth2"
)
Expand Down Expand Up @@ -150,12 +150,12 @@ func userFromReader(r io.Reader, user *goth.User) error {
return nil
}

//RefreshTokenAvailable refresh token is provided by auth provider or not
// RefreshTokenAvailable refresh token is provided by auth provider or not
func (p *Provider) RefreshTokenAvailable() bool {
return true
}

//RefreshToken get new access token based on the refresh token
// RefreshToken get new access token based on the refresh token
func (p *Provider) RefreshToken(refreshToken string) (*oauth2.Token, error) {
token := &oauth2.Token{RefreshToken: refreshToken}
ts := p.config.TokenSource(goth.ContextForClient(p.Client()), token)
Expand Down
5 changes: 3 additions & 2 deletions providers/amazon/amazon_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package amazon_test

import (
"os"
"testing"

"github.com/markbates/goth"
"github.com/markbates/goth/providers/amazon"
"github.com/stretchr/testify/assert"
"os"
"testing"
)

func Test_New(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion providers/amazon/session_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package amazon_test

import (
"testing"

"github.com/markbates/goth"
"github.com/markbates/goth/providers/amazon"
"github.com/stretchr/testify/assert"
"testing"
)

func Test_Implements_Session(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion providers/apple/apple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ nNFzkp23qt9IJDivieB/BBJct1UvhoICg5eZDhSR+x7UH3Uhog8qgoIC
})
a.NoError(err)
a.NotZero(ss)
//fmt.Printf("signed secret: %s", *ss)
// fmt.Printf("signed secret: %s", *ss)
}

func TestAuthorize(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion providers/apple/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string,
if !found {
return nil, errors.New("could not find matching public key")
}
var pubKey *rsa.PublicKey
pubKey := &rsa.PublicKey{}
err = selectedKey.Raw(pubKey)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit cb8f0c2

Please sign in to comment.