Skip to content

Commit

Permalink
added ProviderName and ProviderClient fields to core.RecordAuthWithOA…
Browse files Browse the repository at this point in the history
…uth2Event
  • Loading branch information
ganigeorgiev committed Mar 26, 2023
1 parent f024de3 commit 3a5d3d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@

- Added `migrate history-sync` command to clean `_migrations` history table from deleted migration files references.

- Added `core.RecordAuthWithOAuth2Event.IsNewRecord` bool field to indicate whether the OAuth2 action created a new auth record.
- Added new fields to the `core.RecordAuthWithOAuth2Event` struct:
```
IsNewRecord bool, // boolean field indicating whether the OAuth2 action created a new auth record
ProviderName string, // the name of the OAuth2 provider (eg. "google")
ProviderClient auth.Provider, // the loaded Provider client instance
```
- **!** Renamed `daos.GetTableColumns()` to `daos.TableColumns()` for consistency with the other Dao table related helpers.
Expand Down
2 changes: 2 additions & 0 deletions apis/record_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func (api *recordAuthApi) authWithOAuth2(c echo.Context) error {
event := new(core.RecordAuthWithOAuth2Event)
event.HttpContext = c
event.Collection = collection
event.ProviderName = form.Provider
event.IsNewRecord = false

form.SetBeforeNewRecordCreateFunc(func(createForm *forms.RecordUpsert, authRecord *models.Record, authUser *auth.AuthUser) error {
Expand Down Expand Up @@ -223,6 +224,7 @@ func (api *recordAuthApi) authWithOAuth2(c echo.Context) error {
return func(data *forms.RecordOAuth2LoginData) error {
event.Record = data.Record
event.OAuth2User = data.OAuth2User
event.ProviderClient = data.ProviderClient

return api.app.OnRecordBeforeAuthWithOAuth2Request().Trigger(event, func(e *core.RecordAuthWithOAuth2Event) error {
data.Record = e.Record
Expand Down
10 changes: 6 additions & 4 deletions core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,12 @@ type RecordAuthWithPasswordEvent struct {
type RecordAuthWithOAuth2Event struct {
BaseCollectionEvent

HttpContext echo.Context
Record *models.Record
OAuth2User *auth.AuthUser
IsNewRecord bool
HttpContext echo.Context
ProviderName string
ProviderClient auth.Provider
Record *models.Record
OAuth2User *auth.AuthUser
IsNewRecord bool
}

type RecordAuthRefreshEvent struct {
Expand Down
14 changes: 8 additions & 6 deletions forms/record_oauth2_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (

// RecordOAuth2LoginData defines the OA
type RecordOAuth2LoginData struct {
ExternalAuth *models.ExternalAuth
Record *models.Record
OAuth2User *auth.AuthUser
ExternalAuth *models.ExternalAuth
Record *models.Record
OAuth2User *auth.AuthUser
ProviderClient auth.Provider
}

// BeforeOAuth2RecordCreateFunc defines a callback function that will
Expand Down Expand Up @@ -176,9 +177,10 @@ func (form *RecordOAuth2Login) Submit(
}

interceptorData := &RecordOAuth2LoginData{
ExternalAuth: rel,
Record: authRecord,
OAuth2User: authUser,
ExternalAuth: rel,
Record: authRecord,
OAuth2User: authUser,
ProviderClient: provider,
}

interceptorsErr := runInterceptors(interceptorData, func(newData *RecordOAuth2LoginData) error {
Expand Down

0 comments on commit 3a5d3d5

Please sign in to comment.