Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions internal/controller/connector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ func (cc *ConnectorController) ConnectorRedirect(connector plugin.Connector) (fn
ctx.Redirect(http.StatusFound, "/50x")
return
}
if requirer, ok := connector.(plugin.ConnectorStateRequired); ok && requirer.ConnectorRequireState() && stateInfo == nil {
log.Errorf("missing or invalid connector oauth state for provider %s", connector.ConnectorSlugName())
ctx.Redirect(http.StatusFound, "/50x")
return
}
if stateInfo != nil && stateInfo.Intent == schema.ExternalLoginOAuthStateBindIntent {
if err = cc.userExternalService.BindExternalLoginToUser(ctx, stateInfo.UserID, u); err != nil {
log.Errorf("bind external login failed: %v", err)
Expand Down
1 change: 1 addition & 0 deletions internal/router/plugin_api_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (pr *PluginAPIRouter) RegisterUnAuthConnectorRouter(r *gin.RouterGroup) {
connectorController := pr.connectorController
r.GET(controller.ConnectorLoginRouterPrefix+":name", connectorController.ConnectorLoginDispatcher)
r.GET(controller.ConnectorRedirectRouterPrefix+":name", connectorController.ConnectorRedirectDispatcher)
r.POST(controller.ConnectorRedirectRouterPrefix+":name", connectorController.ConnectorRedirectDispatcher)
r.GET("/connector/info", connectorController.ConnectorsInfo)
r.POST("/connector/binding/email", connectorController.ExternalLoginBindingUserSendEmail)

Expand Down
4 changes: 4 additions & 0 deletions plugin/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ type Connector interface {
ConnectorReceiver(ctx *GinContext, receiverURL string) (userInfo ExternalLoginUserInfo, err error)
}

type ConnectorStateRequired interface {
ConnectorRequireState() bool
}

// ExternalLoginUserInfo external login user info
type ExternalLoginUserInfo struct {
// required. The unique user ID provided by the third-party login
Expand Down