chore: update go-pkgz/auth package

This commit is contained in:
Mrigank Badola
2024-11-10 12:40:07 +05:30
parent 4a39ceee8d
commit 1a27913404
6 changed files with 42 additions and 7 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ require (
github.com/go-chi/chi/v5 v5.1.0
github.com/go-chi/cors v1.2.1
github.com/go-chi/render v1.0.3
github.com/go-pkgz/auth v1.24.2
github.com/go-pkgz/auth v1.24.3-0.20241007090635-78537e6f812d
github.com/go-pkgz/jrpc v0.3.0
github.com/go-pkgz/lcw/v2 v2.0.0
github.com/go-pkgz/lgr v0.11.1
+2 -2
View File
@@ -60,8 +60,8 @@ github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
github.com/go-oauth2/oauth2/v4 v4.5.2 h1:CuZhD3lhGuI6aNLyUbRHXsgG2RwGRBOuCBfd4WQKqBQ=
github.com/go-oauth2/oauth2/v4 v4.5.2/go.mod h1:wk/2uLImWIa9VVQDgxz99H2GDbhmfi/9/Xr+GvkSUSQ=
github.com/go-pkgz/auth v1.24.2 h1:imMjUvTM0c8iOvP/GNGcuNcB/7gF3jFTF9dIPzlAOqI=
github.com/go-pkgz/auth v1.24.2/go.mod h1:xmnzq6g8mhemW1nHnkuByXkBXsHrNf9/qkiVwJugWIs=
github.com/go-pkgz/auth v1.24.3-0.20241007090635-78537e6f812d h1:6iwosbIwyRm7k0lprEv5mFWpGg1qQKLWJNHL088+Bcs=
github.com/go-pkgz/auth v1.24.3-0.20241007090635-78537e6f812d/go.mod h1:xmnzq6g8mhemW1nHnkuByXkBXsHrNf9/qkiVwJugWIs=
github.com/go-pkgz/email v0.5.0 h1:fdtMDGJ8NwyBACLR0LYHaCIK/OeUwZHMhH7Q0+oty9U=
github.com/go-pkgz/email v0.5.0/go.mod h1:BdxglsQnymzhfdbnncEE72a6DrucZHy6I+42LK2jLEc=
github.com/go-pkgz/expirable-cache v0.1.0/go.mod h1:GTrEl0X+q0mPNqN6dtcQXksACnzCBQ5k/k1SwXJsZKs=
+10 -3
View File
@@ -1,7 +1,7 @@
# auth - authentication via oauth2, direct and email
[![Build Status](https://github.com/go-pkgz/auth/workflows/build/badge.svg)](https://github.com/go-pkgz/auth/actions) [![Coverage Status](https://coveralls.io/repos/github/go-pkgz/auth/badge.svg?branch=master)](https://coveralls.io/github/go-pkgz/auth?branch=master) [![godoc](https://godoc.org/github.com/go-pkgz/auth?status.svg)](https://pkg.go.dev/github.com/go-pkgz/auth?tab=doc)
This library provides "social login" with Github, Google, Facebook, Microsoft, Twitter, Yandex, Battle.net, Apple, Patreon and Telegram as well as custom auth providers and email verification.
This library provides "social login" with Github, Google, Facebook, Microsoft, Twitter, Yandex, Battle.net, Apple, Patreon, Discord and Telegram as well as custom auth providers and email verification.
- Multiple oauth2 providers can be used at the same time
- Special `dev` provider allows local testing and development
@@ -144,7 +144,7 @@ In addition to oauth2 providers `auth.Service` allows to use direct user-defined
```go
service.AddDirectProvider("local", provider.CredCheckerFunc(func(user, password string) (ok bool, err error) {
ok, err := checkUserSomehow(user, password)
ok, err = checkUserSomehow(user, password)
return ok, err
}))
```
@@ -205,7 +205,7 @@ used as `Sender`.
The API for this provider:
- `GET /auth/<name>/login?user=<user>&address=<adsress>&aud=<site_id>&from=<url>` - send confirmation request to user
- `GET /auth/<name>/login?user=<user>&address=<address>&aud=<site_id>&from=<url>` - send confirmation request to user
- `GET /auth/<name>/login?token=<conf.token>&sess=[1|0]` - authorize with confirmation token
The provider acts like any other, i.e. will be registered as `/auth/email/login`.
@@ -604,6 +604,13 @@ For more details refer to [Complete Guide of Battle.net OAuth API and Login Butt
1. Under **"Redirect URIs"** enter the correct url constructed as domain + `/auth/patreon/callback`. ie `https://example.mysite.com/auth/patreon/callback`
1. Take note of the **Client ID** and **Client Secret**
#### Discord Auth Provider ####
1. Log into Discord Developer Portal https://discord.com/developers/applications
2. Click on **New Application** to create the application required for Oauth
3. After filling **"NAME"**, navigate to **"OAuth2"** option on the left sidebar
4. Under **"Redirects"** enter the correct url constructed as domain + `/auth/discord/callback`. ie `https://remark42.mysite.com/auth/discord/callback`
5. Take note of the **CLIENT ID** and **CLIENT SECRET**
#### Twitter Auth Provider
1. Create a new twitter application https://developer.twitter.com/en/apps
1. Fill **App name** and **Description** and **URL** of your site
+2
View File
@@ -257,6 +257,8 @@ func (s *Service) addProviderByName(name string, p provider.Params) {
prov = provider.NewTwitter(p)
case "patreon":
prov = provider.NewPatreon(p)
case "discord":
prov = provider.NewDiscord(p)
case "dev":
prov = provider.NewDev(p)
default:
+26
View File
@@ -265,3 +265,29 @@ func NewPatreon(p Params) Oauth2Handler {
},
})
}
// NewDiscord makes discord oauth2 provider
func NewDiscord(p Params) Oauth2Handler {
return initOauth2Handler(p, Oauth2Handler{
name: "discord",
// see https://discord.com/developers/docs/topics/oauth2
endpoint: oauth2.Endpoint{
AuthURL: "https://discord.com/oauth2/authorize",
TokenURL: "https://discord.com/api/oauth2/token",
},
infoURL: "https://discord.com/api/v10/users/@me",
scopes: []string{"identify"},
mapUser: func(data UserData, _ []byte) token.User {
userInfo := token.User{
ID: "discord_" + token.HashID(sha1.New(), data.Value("id")),
Name: data.Value("username"),
Picture: fmt.Sprintf("https://cdn.discordapp.com/avatars/%s/%s.webp", data.Value("id"), data.Value("avatar")),
}
for k, v := range p.UserAttributes {
userInfo.SetStrAttr(v, data.Value(k))
}
return userInfo
},
})
}
+1 -1
View File
@@ -65,7 +65,7 @@ github.com/go-chi/render
github.com/go-oauth2/oauth2/v4
github.com/go-oauth2/oauth2/v4/errors
github.com/go-oauth2/oauth2/v4/server
# github.com/go-pkgz/auth v1.24.2
# github.com/go-pkgz/auth v1.24.3-0.20241007090635-78537e6f812d
## explicit; go 1.21
github.com/go-pkgz/auth
github.com/go-pkgz/auth/avatar