Skip to content

Instantly share code, notes, and snippets.

@kanapuli
Last active October 26, 2017 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanapuli/64d681d264a6336378e9641d1839f123 to your computer and use it in GitHub Desktop.
Save kanapuli/64d681d264a6336378e9641d1839f123 to your computer and use it in GitHub Desktop.
//SlackSignIn gives the Authentication token in return to the code
func (LoginService) SlackSignIn(ctx context.Context, code string) (token SlackTokenResponse, err error) {
conf := &oauth2.Config{
ClientID: slackClientID,
ClientSecret: slackClientSecret,
Scopes: slackScopes,
Endpoint: oauth2.Endpoint{
AuthURL: slackAuthURL,
TokenURL: slackTokenURL,
},
}
httpClient := &http.Client{Timeout: 2 * time.Second}
ctx = context.WithValue(ctx, oauth2.HTTPClient, httpClient)
tok, err := conf.Exchange(ctx, code)
if err != nil {
log.Fatal(err)
}
token = SlackTokenResponse{
AccessToken: tok.AccessToken,
Expiry: tok.Expiry,
RefreshToken: tok.RefreshToken,
TokenType: tok.TokenType,
}
client := conf.Client(ctx, tok)
_ = client
return token, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment