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

chore: Add dev credentials handling to twitter #373

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions recipe/thirdparty/providers/twitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,20 @@ func Twitter(input tpmodels.ProviderInput) *tpmodels.TypeProvider {
}

originalImplementation.ExchangeAuthCodeForOAuthTokens = func(redirectURIInfo tpmodels.TypeRedirectURIInfo, userContext supertokens.UserContext) (tpmodels.TypeOAuthTokens, error) {
basicAuthToken := base64.StdEncoding.EncodeToString([]byte(originalImplementation.Config.ClientID + ":" + originalImplementation.Config.ClientSecret))
clientId := originalImplementation.Config.ClientID
redirectUri := redirectURIInfo.RedirectURIOnProviderDashboard

// We need to do this because we don't call the original implementation
/* Transformation needed for dev keys BEGIN */

if isUsingDevelopmentClientId(clientId) {
clientId = getActualClientIdFromDevelopmentClientId(clientId)
redirectUri = DevOauthRedirectUrl
}

/* Transformation needed for dev keys END */

basicAuthToken := base64.StdEncoding.EncodeToString([]byte(clientId + ":" + originalImplementation.Config.ClientSecret))
twitterOauthParams := map[string]interface{}{}

if originalImplementation.Config.TokenEndpointBodyParams != nil {
Expand All @@ -69,9 +82,9 @@ func Twitter(input tpmodels.ProviderInput) *tpmodels.TypeProvider {
}

twitterOauthParams["grant_type"] = "authorization_code"
twitterOauthParams["client_id"] = originalImplementation.Config.ClientID
twitterOauthParams["client_id"] = clientId
twitterOauthParams["code_verifier"] = codeVerifier
twitterOauthParams["redirect_uri"] = redirectURIInfo.RedirectURIOnProviderDashboard
twitterOauthParams["redirect_uri"] = redirectUri
twitterOauthParams["code"] = redirectURIInfo.RedirectURIQueryParams["code"]

return doPostRequest(originalImplementation.Config.TokenEndpoint, twitterOauthParams, map[string]interface{}{
Expand Down
Loading