Skip to main content

Slack Authorization

1. Create Slack App

create slack app

Then get ClientId and ClientSecret.

  • Add Redirect URLs and Scopes

slack scope

Scopes add users.profile:read, users:read and users:read.email.

  • Install your app

slack install app

warning

Important Note

Client secrets can protect the security of your application, so please ensure that it is not leaked! Also, do not share your client secrets with anyone!!!

2. Integration GAuth

  • Install GAuth
go get github.com/LeoInnovateLab/gauth
  • import register
import (
_ "github.com/LeoInnovateLab/gauth/register"
)
  • Create AuthRequest
authRequest, err := gauth.New().
Source("slack").
ClientId("your_app_id").
ClientSecret("your_app_secret").
RedirectUrl("your_callback_url").
Build()
  • Generate Authorize URL
authorizeUrl, err := authRequest.Authorize(utils.CreateState())

You can use this authorizeUrl to redirect.

3. Authorization

Authorization result


"data": {
"uid": "U0734xxx",
"username": "Leo",
"nickname": "Leo",
"avatar": "https://avatars.slack-edge.com/2024-05-07/7083458955538_ab4691c70b61ab7e6316_original.jpg",
"blog": "",
"company": "",
"location": "",
"email": "[email protected]",
"remark": "",
"gender": -1,
"source": "slack",
"token": {
"access_token": "xoxb-7096124864113-7083663139090",
"expire_in": 0,
"refresh_token": "",
"refresh_token_expire_in": 0,
"uid": "U07347xxxx",
"open_id": "",
"access_code": "",
"union_id": "",
"scope": "users:read,users:read.email,users.profile:read",
"token_type": "bot",
"id_token": "",
"mac_algorithm": "",
"mac_key": "",
"code": "",
"snapshot_user": false,
"oauth_token": "",
"oauth_token_secret": "",
"user_id": "",
"screen_name": "",
"oauth_callback_confirmed": null
},
"raw_user_info": "{\"ok\":true,\"user\":{\"id\":\"U07347xxx\",\"team_id\":\"T072U3xxx\",\"name\":\"leo\",\"deleted\":false,\"color\":\"9f69e7\",\"real_name\":\"Leo\",\"tz\":\"Asia\\/Chongqing\",\"tz_label\":\"China Standard Time\",\"tz_offset\":28800,\"profile\":{\"title\":\"\",\"phone\":\"\",\"skype\":\"\",\"real_name\":\"Leo\",\"real_name_normalized\":\"Leo Lau\",\"display_name\":\"\",\"display_name_normalized\":\"\",\"fields\":null,\"status_text\":\"\",\"status_emoji\":\"\",\"status_emoji_display_info\":[],\"status_expiration\":0,\"avatar_hash\":\"ab4691c\",\"image_original\":\"https:\\/\\/avatars.slack-edge.com\\/2024-05-07\\/7083458955538_ab4691c70b61ab7e6316_original.jpg\",\"is_custom_image\":true,\"email\":\"[email protected]\",\"first_name\":\"Leo\",\"last_name\":\"\",\"image_24\":\"https:\\/\\/avatars.slack-edge.com\\/2024-05-07\\/7083458955538_ab4691c70b61ab7e6316_24.jpg\",\"image_32\":\"https:\\/\\/avatars.slack-edge.com\\/2024-05-07\\/7083458955538_ab4691c70b61ab7e6316_32.jpg\",\"image_48\":\"https:\\/\\/avatars.slack-edge.com\\/2024-05-07\\/7083458955538_ab4691c70b61ab7e6316_48.jpg\",\"image_72\":\"https:\\/\\/avatars.slack-edge.com\\/2024-05-07\\/7083458955538_ab4691c70b61ab7e6316_72.jpg\",\"image_192\":\"https:\\/\\/avatars.slack-edge.com\\/2024-05-07\\/7083458955538_ab4691c70b61ab7e6316_192.jpg\",\"image_512\":\"https:\\/\\/avatars.slack-edge.com\\/2024-05-07\\/7083458955538_ab4691c70b61ab7e6316_512.jpg\",\"image_1024\":\"https:\\/\\/avatars.slack-edge.com\\/2024-05-07\\/7083458955538_ab4691c70b61ab7e6316_1024.jpg\",\"status_text_canonical\":\"\",\"team\":\"T072U3xxxx\"},\"is_admin\":true,\"is_owner\":true,\"is_primary_owner\":true,\"is_restricted\":false,\"is_ultra_restricted\":false,\"is_bot\":false,\"is_app_user\":false,\"updated\":1715133779,\"is_email_confirmed\":true,\"who_can_share_contact_card\":\"EVERYONE\"}}",
"snapshot_user": false
}
}

Demo

Recommend using GAuth Demo for testing.

  • Fill in the requested App Id and App secrets in .env.demo

  • Then, Start project, visit http://localhost:8080/

Demo