Skip to content

Commit

Permalink
Fix slack_user_center
Browse files Browse the repository at this point in the history
  • Loading branch information
Anan1225 authored and LinkinStars committed Oct 16, 2024
1 parent 90d3920 commit 262cf43
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions user-center-slack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Config

To use this plugin, you need to create [a Slack App](https://api.slack.com/quickstart) first, set the Scope and Redirect URL correctly, and copy the `Client ID`, `Client Secrect`, `Signing Secret` and `Webhook URL`. To activate the Slash Command function, you also need to set the `slash command` in your app. Here are some examples:
To use this plugin, you need to create [a Slack App](https://api.slack.com/quickstart) first, set the Scope and Redirect URL correctly, and copy the `Client ID`, `Client Secrect`, `Signing Secret` and `Webhook URL`. To activate the Slash Command function, you also need to set the `slash command` in your app. Here are default settings you can try:

> Scope: chat:write, commands, groups:write, im:write, incoming-webhook, mpim:write, users:read, users:read.email
>
Expand All @@ -15,7 +15,7 @@ To use this plugin, you need to create [a Slack App](https://api.slack.com/quick
> Slash command:
>
> * Command: /ask
> * Requesti URL: https://Your_Site_URL/answer/api/v1/importer/command
> * Requesti URL: https://Your_Site_URL/answer/api/v1/slack/slash
> * Usage Hint: [Title][Content\][Tag1,Tag2...\]

Expand Down
2 changes: 1 addition & 1 deletion user-center-slack/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewRespBodyData(code int, reason string, data interface{}) *RespBody {
func (uc *UserCenter) BuildSlackBaseRedirectURL() string {
clientID := uc.Config.ClientID
log.Debug("Get client ID:", clientID)
scope := "chat:write,commands,groups:write,im:write,incoming-webhook,mpim:write,users:read,users:read.email" // 需要的权限范围
scope := "chat:write,commands,groups:write,im:write,incoming-webhook,mpim:write,users:read,users:read.email"
response_type := "code"
redirect_uri := fmt.Sprintf("%s/answer/api/v1/user-center/login/callback", plugin.SiteURL())

Expand Down
9 changes: 9 additions & 0 deletions user-center-slack/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ func NewWebhookReq(content string) *WebhookReq {
},
}
}

type SlackUserResponse struct {
Ok bool `json:"ok"`
User struct {
Profile struct {
Email string `json:"email"`
} `json:"profile"`
} `json:"user"`
}
10 changes: 0 additions & 10 deletions user-center-slack/slack_user_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ var Info embed.FS

type Importer struct{}

type SlackUserResponse struct {
Ok bool `json:"ok"`
User struct {
Profile struct {
Email string `json:"email"`
} `json:"profile"`
} `json:"user"`
}

type UserCenter struct {
Config *UserCenterConfig
SlackClient *SlackClient
Expand Down Expand Up @@ -192,7 +183,6 @@ func (uc *UserCenter) LoginCallback(ctx *plugin.GinContext) (userInfo *plugin.Us
//Get Email
if len(info.Profile.Email) == 0 {
ctx.Redirect(http.StatusFound, "/user-center/auth-failed")
ctx.Abort()
return nil, fmt.Errorf("user email is empty")
}

Expand Down

0 comments on commit 262cf43

Please sign in to comment.