Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openid connect #1242

Merged
merged 3 commits into from
Feb 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 32 additions & 2 deletions oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -137,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},
Expand All @@ -156,3 +165,24 @@ func RefreshOAuthV2TokenContext(ctx context.Context, client httpClient, clientID
}
return response, response.Err()
}

// 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)
}

// 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()
}