Skip to content

Commit

Permalink
Add dev credentials handling to twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
nkshah2 committed Sep 26, 2023
1 parent 0260767 commit a3b8603
Showing 1 changed file with 16 additions and 3 deletions.
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

0 comments on commit a3b8603

Please sign in to comment.