added ProviderName and ProviderClient fields to core.RecordAuthWithOAuth2Event
This commit is contained in:
		
							parent
							
								
									f024de3cc4
								
							
						
					
					
						commit
						3a5d3d521f
					
				| 
						 | 
					@ -28,7 +28,12 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Added `migrate history-sync` command to clean `_migrations` history table from deleted migration files references.
 | 
					- 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.
 | 
					- **!** Renamed `daos.GetTableColumns()` to `daos.TableColumns()` for consistency with the other Dao table related helpers.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -180,6 +180,7 @@ func (api *recordAuthApi) authWithOAuth2(c echo.Context) error {
 | 
				
			||||||
	event := new(core.RecordAuthWithOAuth2Event)
 | 
						event := new(core.RecordAuthWithOAuth2Event)
 | 
				
			||||||
	event.HttpContext = c
 | 
						event.HttpContext = c
 | 
				
			||||||
	event.Collection = collection
 | 
						event.Collection = collection
 | 
				
			||||||
 | 
						event.ProviderName = form.Provider
 | 
				
			||||||
	event.IsNewRecord = false
 | 
						event.IsNewRecord = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	form.SetBeforeNewRecordCreateFunc(func(createForm *forms.RecordUpsert, authRecord *models.Record, authUser *auth.AuthUser) error {
 | 
						form.SetBeforeNewRecordCreateFunc(func(createForm *forms.RecordUpsert, authRecord *models.Record, authUser *auth.AuthUser) error {
 | 
				
			||||||
| 
						 | 
					@ -223,6 +224,7 @@ func (api *recordAuthApi) authWithOAuth2(c echo.Context) error {
 | 
				
			||||||
		return func(data *forms.RecordOAuth2LoginData) error {
 | 
							return func(data *forms.RecordOAuth2LoginData) error {
 | 
				
			||||||
			event.Record = data.Record
 | 
								event.Record = data.Record
 | 
				
			||||||
			event.OAuth2User = data.OAuth2User
 | 
								event.OAuth2User = data.OAuth2User
 | 
				
			||||||
 | 
								event.ProviderClient = data.ProviderClient
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return api.app.OnRecordBeforeAuthWithOAuth2Request().Trigger(event, func(e *core.RecordAuthWithOAuth2Event) error {
 | 
								return api.app.OnRecordBeforeAuthWithOAuth2Request().Trigger(event, func(e *core.RecordAuthWithOAuth2Event) error {
 | 
				
			||||||
				data.Record = e.Record
 | 
									data.Record = e.Record
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -205,10 +205,12 @@ type RecordAuthWithPasswordEvent struct {
 | 
				
			||||||
type RecordAuthWithOAuth2Event struct {
 | 
					type RecordAuthWithOAuth2Event struct {
 | 
				
			||||||
	BaseCollectionEvent
 | 
						BaseCollectionEvent
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	HttpContext echo.Context
 | 
						HttpContext    echo.Context
 | 
				
			||||||
	Record      *models.Record
 | 
						ProviderName   string
 | 
				
			||||||
	OAuth2User  *auth.AuthUser
 | 
						ProviderClient auth.Provider
 | 
				
			||||||
	IsNewRecord bool
 | 
						Record         *models.Record
 | 
				
			||||||
 | 
						OAuth2User     *auth.AuthUser
 | 
				
			||||||
 | 
						IsNewRecord    bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type RecordAuthRefreshEvent struct {
 | 
					type RecordAuthRefreshEvent struct {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,9 +18,10 @@ import (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// RecordOAuth2LoginData defines the OA
 | 
					// RecordOAuth2LoginData defines the OA
 | 
				
			||||||
type RecordOAuth2LoginData struct {
 | 
					type RecordOAuth2LoginData struct {
 | 
				
			||||||
	ExternalAuth *models.ExternalAuth
 | 
						ExternalAuth   *models.ExternalAuth
 | 
				
			||||||
	Record       *models.Record
 | 
						Record         *models.Record
 | 
				
			||||||
	OAuth2User   *auth.AuthUser
 | 
						OAuth2User     *auth.AuthUser
 | 
				
			||||||
 | 
						ProviderClient auth.Provider
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// BeforeOAuth2RecordCreateFunc defines a callback function that will
 | 
					// BeforeOAuth2RecordCreateFunc defines a callback function that will
 | 
				
			||||||
| 
						 | 
					@ -176,9 +177,10 @@ func (form *RecordOAuth2Login) Submit(
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	interceptorData := &RecordOAuth2LoginData{
 | 
						interceptorData := &RecordOAuth2LoginData{
 | 
				
			||||||
		ExternalAuth: rel,
 | 
							ExternalAuth:   rel,
 | 
				
			||||||
		Record:       authRecord,
 | 
							Record:         authRecord,
 | 
				
			||||||
		OAuth2User:   authUser,
 | 
							OAuth2User:     authUser,
 | 
				
			||||||
 | 
							ProviderClient: provider,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	interceptorsErr := runInterceptors(interceptorData, func(newData *RecordOAuth2LoginData) error {
 | 
						interceptorsErr := runInterceptors(interceptorData, func(newData *RecordOAuth2LoginData) error {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue