Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor oauth relying party code #4208

Merged
merged 30 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
29ead28
Move OAuth provider config to a separate package
louischan-oursky May 9, 2024
d779046
Move access_token.go to oauthrelyingpartyutil
louischan-oursky May 9, 2024
d4c7a17
Move user_profile.go to oauthrelyingpartyutil
louischan-oursky May 9, 2024
1bf0236
Move authurl.go to oauthrelyingpartyutil
louischan-oursky May 10, 2024
dfece4f
Remove dependency on pkg/lib/config in legacy implementations
louischan-oursky May 10, 2024
c567882
Remove unnecessary interfaces NonOpenIDConnectProvider and OpenIDConn…
louischan-oursky May 10, 2024
234f9c0
Remove GetPrompt from the interface
louischan-oursky May 10, 2024
176752a
Rename GetAuthURL to GetAuthorizationURL
louischan-oursky May 10, 2024
5d55032
Move GetAuthorizationURLOptions to oauthrelyingparty
louischan-oursky May 10, 2024
120cffb
Merge OAuthAuthorizationResponse into GetAuthInfoParam
louischan-oursky May 10, 2024
8b11031
Rename GetAuthInfo to GetUserProfile
louischan-oursky May 10, 2024
20ff1b2
Avoid using stdattrs.T in UserProfile
louischan-oursky May 10, 2024
edef218
Call NewOAuthProvider as late as possible
louischan-oursky May 10, 2024
44cab8c
Move GetUserProfileOptions and UserProfile to oauthrelyingparty
louischan-oursky May 10, 2024
555612e
Change OAuthProviderFactory to work like a provider
louischan-oursky May 10, 2024
ca5c558
Remove Config() from OAuthProvider
louischan-oursky May 10, 2024
2646883
Move standard attributes normalization out of OAuthProvider
louischan-oursky May 10, 2024
b20bbc7
Remove all fields from implementation structs
louischan-oursky May 10, 2024
afe5eb2
Move wechat_authinfo to wechat
louischan-oursky May 10, 2024
76c8233
Move oidc.go to oauthrelyingpartyutil
louischan-oursky May 10, 2024
6b2a401
Move implementations to oauthrelyingparty
louischan-oursky May 10, 2024
1e4cb06
Import provider in tests
louischan-oursky May 10, 2024
d4d45d3
Workaround import cycle
louischan-oursky May 10, 2024
4f1d67e
Hide Scope() in interface
louischan-oursky May 10, 2024
63345a4
Switch to depend on github.com/authgear/oauthrelyingparty
louischan-oursky May 13, 2024
5d3494f
Use goimports instead of go fmt
louischan-oursky May 13, 2024
d54d90f
Run make fmt
louischan-oursky May 13, 2024
7ce1975
Fix compilation errors after rebase
louischan-oursky May 14, 2024
9e451b6
Move Normalizer to internalinterface to solve import cycle
louischan-oursky May 14, 2024
5d13b08
Fix oauth provider not registered in e2e executable
louischan-oursky May 14, 2024
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
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ vendor:
go install github.com/golang/mock/mockgen
go install github.com/google/wire/cmd/wire
go install golang.org/x/vuln/cmd/govulncheck@latest
go install golang.org/x/tools/cmd/goimports@latest
npm --prefix ./scripts/npm ci
npm --prefix ./authui ci
npm --prefix ./portal ci
Expand Down Expand Up @@ -57,7 +58,8 @@ lint:

.PHONY: fmt
fmt:
go fmt ./...
# Ignore generated files, such as wire_gen.go and *_mock_test.go
find ./pkg ./cmd ./e2e -name '*.go' -not -name 'wire_gen.go' -not -name '*_mock_test.go' | sort | xargs goimports -w -format-only -local github.com/authgear/authgear-server

.PHONY: govulncheck
govulncheck:
Expand Down
1 change: 1 addition & 0 deletions cmd/authgear/background/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package background

import (
"context"

"github.com/google/wire"

"github.com/authgear/authgear-server/pkg/lib/config"
Expand Down
9 changes: 9 additions & 0 deletions cmd/authgear/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import (
_ "github.com/authgear/authgear-server/cmd/authgear/cmd/cmdstart"
_ "github.com/authgear/authgear-server/pkg/latte"
_ "github.com/authgear/authgear-server/pkg/lib/authenticationflow/declarative"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/adfs"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/apple"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/azureadb2c"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/azureadv2"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/facebook"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/github"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/google"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/linkedin"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/wechat"
"github.com/authgear/authgear-server/pkg/util/debug"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/portal/analytic/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ package analytic
import (
"context"

"github.com/google/wire"

"github.com/authgear/authgear-server/pkg/lib/analytic"
"github.com/authgear/authgear-server/pkg/lib/config"
"github.com/authgear/authgear-server/pkg/lib/infra/db"
"github.com/authgear/authgear-server/pkg/lib/infra/redis"
"github.com/authgear/authgear-server/pkg/util/clock"
"github.com/authgear/authgear-server/pkg/util/periodical"
"github.com/google/wire"
)

func NewUserWeeklyReport(
Expand Down
1 change: 1 addition & 0 deletions cmd/portal/cmd/cmdanalytic/posthog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmdanalytic

import (
"context"

"github.com/spf13/cobra"

"github.com/authgear/authgear-server/cmd/portal/analytic"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"fmt"
"log"

portalcmd "github.com/authgear/authgear-server/cmd/portal/cmd"
"github.com/authgear/authgear-server/cmd/portal/internal"
"github.com/spf13/cobra"
"sigs.k8s.io/yaml"

portalcmd "github.com/authgear/authgear-server/cmd/portal/cmd"
"github.com/authgear/authgear-server/cmd/portal/internal"
)

var cmdInternalMigrateRemoveIsFirstParty = &cobra.Command{
Expand Down
9 changes: 9 additions & 0 deletions cmd/portal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ import (
_ "github.com/authgear/authgear-server/cmd/portal/cmd/cmdpricing"
_ "github.com/authgear/authgear-server/cmd/portal/cmd/cmdstart"
_ "github.com/authgear/authgear-server/cmd/portal/cmd/cmdusage"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/adfs"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/apple"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/azureadb2c"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/azureadv2"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/facebook"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/github"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/google"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/linkedin"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/wechat"
"github.com/authgear/authgear-server/pkg/util/debug"
)

Expand Down
1 change: 1 addition & 0 deletions cmd/portal/server/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package server

import (
"context"

"github.com/google/wire"

"github.com/authgear/authgear-server/pkg/lib/config"
Expand Down
3 changes: 2 additions & 1 deletion cmd/portal/usage/deps.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package usage

import (
"github.com/google/wire"

"github.com/authgear/authgear-server/pkg/lib/config"
"github.com/authgear/authgear-server/pkg/lib/infra/db/auditdb"
"github.com/authgear/authgear-server/pkg/lib/infra/db/globaldb"
"github.com/authgear/authgear-server/pkg/lib/infra/redis/analyticredis"
"github.com/authgear/authgear-server/pkg/lib/meter"
"github.com/authgear/authgear-server/pkg/lib/usage"
"github.com/authgear/authgear-server/pkg/util/cobrasentry"
"github.com/google/wire"
)

func NewGlobalDatabaseCredentials(dbCredentials *config.DatabaseCredentials) *config.GlobalDatabaseCredentialsEnvironmentConfig {
Expand Down
3 changes: 2 additions & 1 deletion cmd/portal/usage/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (

"github.com/getsentry/sentry-go"

"github.com/google/wire"

"github.com/authgear/authgear-server/pkg/lib/config"
"github.com/authgear/authgear-server/pkg/lib/infra/db"
"github.com/authgear/authgear-server/pkg/lib/infra/redis"
"github.com/authgear/authgear-server/pkg/lib/usage"
"github.com/google/wire"
)

func NewCountCollector(
Expand Down
3 changes: 2 additions & 1 deletion e2e/cmd/e2e/cmd/configsource.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
e2e "github.com/authgear/authgear-server/e2e/cmd/e2e/pkg"
"github.com/spf13/cobra"

e2e "github.com/authgear/authgear-server/e2e/cmd/e2e/pkg"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion e2e/cmd/e2e/cmd/execsql.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
e2e "github.com/authgear/authgear-server/e2e/cmd/e2e/pkg"
"github.com/spf13/cobra"

e2e "github.com/authgear/authgear-server/e2e/cmd/e2e/pkg"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion e2e/cmd/e2e/cmd/otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package cmd
import (
"fmt"

e2e "github.com/authgear/authgear-server/e2e/cmd/e2e/pkg"
"github.com/spf13/cobra"

e2e "github.com/authgear/authgear-server/e2e/cmd/e2e/pkg"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion e2e/cmd/e2e/cmd/userimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package cmd
import (
"os"

e2e "github.com/authgear/authgear-server/e2e/cmd/e2e/pkg"
"github.com/spf13/cobra"

e2e "github.com/authgear/authgear-server/e2e/cmd/e2e/pkg"
)

func init() {
Expand Down
14 changes: 12 additions & 2 deletions e2e/cmd/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ import (
"log"
"os"

cmd "github.com/authgear/authgear-server/e2e/cmd/e2e/cmd"
"github.com/authgear/authgear-server/pkg/util/debug"
"github.com/joho/godotenv"
_ "go.uber.org/automaxprocs"

cmd "github.com/authgear/authgear-server/e2e/cmd/e2e/cmd"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/adfs"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/apple"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/azureadb2c"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/azureadv2"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/facebook"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/github"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/google"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/linkedin"
_ "github.com/authgear/authgear-server/pkg/lib/oauthrelyingparty/wechat"
"github.com/authgear/authgear-server/pkg/util/debug"
)

func main() {
Expand Down
3 changes: 2 additions & 1 deletion e2e/cmd/e2e/pkg/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package e2e
import (
"net/http"

"github.com/google/wire"

deps "github.com/authgear/authgear-server/pkg/lib/deps"
"github.com/authgear/authgear-server/pkg/util/httputil"
"github.com/google/wire"
)

func ProvideEnd2EndHTTPRequest() *http.Request {
Expand Down
5 changes: 3 additions & 2 deletions e2e/cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"os/signal"
"time"

"github.com/authgear/authgear-server/e2e/cmd/proxy/mockoidc"
"github.com/authgear/authgear-server/e2e/cmd/proxy/modifier"
"github.com/google/martian"
"github.com/google/martian/httpspec"
"github.com/google/martian/mitm"

"github.com/authgear/authgear-server/e2e/cmd/proxy/mockoidc"
"github.com/authgear/authgear-server/e2e/cmd/proxy/modifier"
)

func main() {
Expand Down
3 changes: 2 additions & 1 deletion e2e/cmd/proxy/modifier/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"net/http"
"net/url"

"github.com/authgear/authgear-server/e2e/cmd/proxy/mockoidc"
"github.com/google/martian/parse"

"github.com/authgear/authgear-server/e2e/cmd/proxy/mockoidc"
)

func init() {
Expand Down
1 change: 1 addition & 0 deletions e2e/pkg/testrunner/testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
texttemplate "text/template"

"github.com/Masterminds/sprig"

authflowclient "github.com/authgear/authgear-server/e2e/pkg/e2eclient"
"github.com/authgear/authgear-server/pkg/util/httputil"
)
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

require github.com/go-jose/go-jose/v3 v3.0.3
require (
github.com/authgear/oauthrelyingparty v1.0.0
github.com/go-jose/go-jose/v3 v3.0.3
)

require (
cloud.google.com/go v0.110.8 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ github.com/alicebob/miniredis/v2 v2.31.0 h1:ObEFUNlJwoIiyjxdrYF0QIDE7qXcLc7D3WpS
github.com/alicebob/miniredis/v2 v2.31.0/go.mod h1:UB/T2Uztp7MlFSDakaX1sTXUv5CASoprx0wulRT6HBg=
github.com/authgear/graphql-go-relay v0.0.0-20201016065100-df672205b892 h1:OIPk6DEk51wL35vsCYfLacc7pZ0ev8TKvmcp+EKOnPU=
github.com/authgear/graphql-go-relay v0.0.0-20201016065100-df672205b892/go.mod h1:SxJGRjo7+1SFr8pfMghiCM17WWFSswRwMvtv6t1aDO8=
github.com/authgear/oauthrelyingparty v1.0.0 h1:i5F3mjnImWesbdOc7ZcjPcT5918FAwruduRmFTBMtdY=
github.com/authgear/oauthrelyingparty v1.0.0/go.mod h1:0UcO0p5eS9BPLulX6K7TvkXkuPeTn3QhAJ/UQg4fmiQ=
github.com/aws/aws-sdk-go v1.47.9 h1:rarTsos0mA16q+huicGx0e560aYRtOucV5z2Mw23JRY=
github.com/aws/aws-sdk-go v1.47.9/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
Expand Down
3 changes: 2 additions & 1 deletion pkg/admin/graphql/group_mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package graphql
import (
relay "github.com/authgear/graphql-go-relay"

"github.com/graphql-go/graphql"

"github.com/authgear/authgear-server/pkg/api/apierrors"
"github.com/authgear/authgear-server/pkg/api/event/nonblocking"
"github.com/authgear/authgear-server/pkg/api/model"
"github.com/authgear/authgear-server/pkg/lib/rolesgroups"
"github.com/authgear/authgear-server/pkg/util/graphqlutil"
"github.com/authgear/authgear-server/pkg/util/slice"
"github.com/graphql-go/graphql"
)

var createGroupInput = graphql.NewInputObject(graphql.InputObjectConfig{
Expand Down
3 changes: 2 additions & 1 deletion pkg/admin/graphql/group_role_mutation.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package graphql

import (
"github.com/graphql-go/graphql"

"github.com/authgear/authgear-server/pkg/api/event/nonblocking"
"github.com/authgear/authgear-server/pkg/api/model"
"github.com/authgear/authgear-server/pkg/lib/rolesgroups"
"github.com/authgear/authgear-server/pkg/util/graphqlutil"
"github.com/authgear/authgear-server/pkg/util/slice"
"github.com/graphql-go/graphql"
)

var addRoleToGroupsInput = graphql.NewInputObject(graphql.InputObjectConfig{
Expand Down
5 changes: 3 additions & 2 deletions pkg/admin/graphql/group_user_mutation.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package graphql

import (
relay "github.com/authgear/graphql-go-relay"
"github.com/graphql-go/graphql"

"github.com/authgear/authgear-server/pkg/api/apierrors"
"github.com/authgear/authgear-server/pkg/api/event/nonblocking"
"github.com/authgear/authgear-server/pkg/api/model"
"github.com/authgear/authgear-server/pkg/lib/rolesgroups"
"github.com/authgear/authgear-server/pkg/util/graphqlutil"
"github.com/authgear/authgear-server/pkg/util/slice"
relay "github.com/authgear/graphql-go-relay"
"github.com/graphql-go/graphql"
)

var addGroupToUsersInput = graphql.NewInputObject(graphql.InputObjectConfig{
Expand Down
3 changes: 2 additions & 1 deletion pkg/admin/graphql/role_mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package graphql
import (
relay "github.com/authgear/graphql-go-relay"

"github.com/graphql-go/graphql"

"github.com/authgear/authgear-server/pkg/api/apierrors"
"github.com/authgear/authgear-server/pkg/api/event/nonblocking"
"github.com/authgear/authgear-server/pkg/api/model"
"github.com/authgear/authgear-server/pkg/lib/rolesgroups"
"github.com/authgear/authgear-server/pkg/util/graphqlutil"
"github.com/authgear/authgear-server/pkg/util/slice"
"github.com/graphql-go/graphql"
)

var createRoleInput = graphql.NewInputObject(graphql.InputObjectConfig{
Expand Down
5 changes: 3 additions & 2 deletions pkg/admin/graphql/role_user_mutation.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package graphql

import (
relay "github.com/authgear/graphql-go-relay"
"github.com/graphql-go/graphql"

"github.com/authgear/authgear-server/pkg/api/apierrors"
"github.com/authgear/authgear-server/pkg/api/event/nonblocking"
"github.com/authgear/authgear-server/pkg/api/model"
"github.com/authgear/authgear-server/pkg/lib/rolesgroups"
"github.com/authgear/authgear-server/pkg/util/graphqlutil"
"github.com/authgear/authgear-server/pkg/util/slice"
relay "github.com/authgear/graphql-go-relay"
"github.com/graphql-go/graphql"
)

var addRoleToUsersInput = graphql.NewInputObject(graphql.InputObjectConfig{
Expand Down
6 changes: 6 additions & 0 deletions pkg/api/internalinterface/loginid_normalizer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package internalinterface

type LoginIDNormalizer interface {
Normalize(loginID string) (string, error)
ComputeUniqueKey(normalizeLoginID string) (string, error)
}
3 changes: 2 additions & 1 deletion pkg/api/model/siwe.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"encoding/hex"
"fmt"

"github.com/authgear/authgear-server/pkg/util/web3"
"github.com/ethereum/go-ethereum/crypto"

"github.com/authgear/authgear-server/pkg/util/web3"
)

type SIWEPublicKey string
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/model/siwe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"crypto/rand"
"testing"

"github.com/authgear/authgear-server/pkg/api/model"
. "github.com/smartystreets/goconvey/convey"

"github.com/authgear/authgear-server/pkg/api/model"

"github.com/ethereum/go-ethereum/crypto"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/auth/handler/api/authenticationflow_v1_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/http"
"net/url"

"github.com/iawaknahc/jsonschema/pkg/jsonpointer"

"github.com/authgear/authgear-server/pkg/api"
authflow "github.com/authgear/authgear-server/pkg/lib/authenticationflow"
"github.com/authgear/authgear-server/pkg/lib/infra/redis/appredis"
Expand All @@ -17,7 +19,6 @@ import (
"github.com/authgear/authgear-server/pkg/util/log"
"github.com/authgear/authgear-server/pkg/util/slice"
"github.com/authgear/authgear-server/pkg/util/validation"
"github.com/iawaknahc/jsonschema/pkg/jsonpointer"
)

func ConfigureAuthenticationFlowV1CreateRoute(route httproute.Route) httproute.Route {
Expand Down
Loading
Loading