From f2fe7b3abac6ebff05446a55760678db783d74e2 Mon Sep 17 00:00:00 2001 From: Daniel Michaels Date: Mon, 6 Nov 2023 20:30:25 +1100 Subject: [PATCH 1/3] Create openid.connect.token function to fetch access token --- oauth.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/oauth.go b/oauth.go index 94b6546d5..950b743bd 100644 --- a/oauth.go +++ b/oauth.go @@ -69,6 +69,15 @@ type OAuthV2ResponseAuthedUser struct { TokenType string `json:"token_type"` } +// OpenIDConnectResponse ... +type OpenIDConnectResponse struct { + Ok bool `json:"ok"` + AccessToken string `json:"access_token"` + TokenType string `json:"token_type"` + IdToken string `json:"id_token"` + SlackResponse +} + // GetOAuthToken retrieves an AccessToken func GetOAuthToken(client httpClient, clientID, clientSecret, code, redirectURI string) (accessToken string, scope string, err error) { return GetOAuthTokenContext(context.Background(), client, clientID, clientSecret, code, redirectURI) @@ -156,3 +165,24 @@ func RefreshOAuthV2TokenContext(ctx context.Context, client httpClient, clientID } return response, response.Err() } + +// GetOpenIDConnectToken gets a temporary OAuth verifier code for an access token for Sign in with Slack. +// see: https://api.slack.com/methods/openid.connect.token +func GetOpenIDConnectToken(client httpClient, clientID, clientSecret, code, redirectURI string) (resp *OpenIDConnectResponse, err error) { + return GetOpenIDConnectTokenContext(context.Background(), client, clientID, clientSecret, code, redirectURI) +} + +// GetOpenIDConnectTokenContext with a context, gets an access token for Sign in with Slack. +func GetOpenIDConnectTokenContext(ctx context.Context, client httpClient, clientID, clientSecret, code, redirectURI string) (resp *OpenIDConnectResponse, err error) { + values := url.Values{ + "client_id": {clientID}, + "client_secret": {clientSecret}, + "code": {code}, + "redirect_uri": {redirectURI}, + } + response := &OpenIDConnectResponse{} + if err = postForm(ctx, client, APIURL+"openid.connect.token", values, response, discard{}); err != nil { + return nil, err + } + return response, response.Err() +} From 311e30dab2208c58ef89dc5340d723250918afcd Mon Sep 17 00:00:00 2001 From: Daniel Michaels Date: Mon, 6 Nov 2023 20:30:51 +1100 Subject: [PATCH 2/3] Fix incorrectly commented functions --- oauth.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oauth.go b/oauth.go index 950b743bd..851820a64 100644 --- a/oauth.go +++ b/oauth.go @@ -146,12 +146,12 @@ func GetOAuthV2ResponseContext(ctx context.Context, client httpClient, clientID, return response, response.Err() } -// RefreshOAuthV2AccessContext with a context, gets a V2 OAuth access token response +// RefreshOAuthV2Token with a context, gets a V2 OAuth access token response func RefreshOAuthV2Token(client httpClient, clientID, clientSecret, refreshToken string) (resp *OAuthV2Response, err error) { return RefreshOAuthV2TokenContext(context.Background(), client, clientID, clientSecret, refreshToken) } -// RefreshOAuthV2AccessContext with a context, gets a V2 OAuth access token response +// RefreshOAuthV2TokenContext with a context, gets a V2 OAuth access token response func RefreshOAuthV2TokenContext(ctx context.Context, client httpClient, clientID, clientSecret, refreshToken string) (resp *OAuthV2Response, err error) { values := url.Values{ "client_id": {clientID}, From 8019a9a7724c28b9486d0791c2c74d588f23e9a4 Mon Sep 17 00:00:00 2001 From: Daniel Michaels Date: Mon, 6 Nov 2023 20:53:31 +1100 Subject: [PATCH 3/3] Improved comment for GetOpenIDConnectToken --- oauth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oauth.go b/oauth.go index 851820a64..3c853faea 100644 --- a/oauth.go +++ b/oauth.go @@ -166,7 +166,7 @@ func RefreshOAuthV2TokenContext(ctx context.Context, client httpClient, clientID return response, response.Err() } -// GetOpenIDConnectToken gets a temporary OAuth verifier code for an access token for Sign in with Slack. +// GetOpenIDConnectToken exchanges a temporary OAuth verifier code for an access token for Sign in with Slack. // see: https://api.slack.com/methods/openid.connect.token func GetOpenIDConnectToken(client httpClient, clientID, clientSecret, code, redirectURI string) (resp *OpenIDConnectResponse, err error) { return GetOpenIDConnectTokenContext(context.Background(), client, clientID, clientSecret, code, redirectURI)