Skip to content

Commit

Permalink
Merge pull request #720 from supertokens/twitter-provider
Browse files Browse the repository at this point in the history
Add docs for Twitter provider
  • Loading branch information
rishabhpoddar authored Sep 27, 2023
2 parents e84495d + 93895dc commit ee1feb2
Show file tree
Hide file tree
Showing 9 changed files with 885 additions and 3 deletions.
2 changes: 1 addition & 1 deletion v2/src/plugins/codeTypeChecking/goEnv/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-chi/cors v1.2.1
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/supertokens/supertokens-golang v0.14.0
github.com/supertokens/supertokens-golang v0.15.0
)

require (
Expand Down
2 changes: 1 addition & 1 deletion v2/src/plugins/codeTypeChecking/jsEnv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"socket.io": "^4.6.1",
"socketio": "^1.0.0",
"supertokens-auth-react": "^0.35.0",
"supertokens-node": "^16.0.0",
"supertokens-node": "^16.1.0",
"supertokens-node7": "npm:[email protected]",
"supertokens-react-native": "^4.0.0",
"supertokens-web-js": "^0.8.0",
Expand Down
2 changes: 1 addition & 1 deletion v2/src/theme/TOC/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function OldDocsDisclaimer() {
<div className={styles.tocOldDOcsTop}>
<img src="/img/ic-binoculars.svg" className={styles.tocOldDocsIcon} />
<span className={styles.tocOldDocsText}>
Looking for older version of the documentation?
Looking for older versions of the documentation?
</span>
</div>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SuperTokens currently supports the following providers, but you can also [add yo
- Github (`thirdPartyId: "github"`)
- Google (`thirdPartyId: "google"`)
- LinkedIn (`thirdPartyId: "linkedin"`)
- Twitter (`thirdPartyId: "twitter"`)

## Step 1: Frontend setup

Expand Down
293 changes: 293 additions & 0 deletions v2/thirdparty/common-customizations/sign-in-and-up/provider-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,299 @@ curl --location --request PUT '^{coreInjector_uri_without_quotes}/<TENANT_ID>/re

</MultiSingleTenant>

## Twitter

<MultiSingleTenant>

<TabItem value="single">

<BackendSDKTabs isSubTab={true}>
<TabItem value="nodejs">

```tsx
import SuperTokens from "supertokens-node";
import ^{recipeNameCapitalLetters} from "supertokens-node/recipe/^{codeImportRecipeName}";

SuperTokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
supertokens: {
connectionURI: "...",
},
recipeList: [
^{recipeNameCapitalLetters}.init({
^{nodeRecipeInitDefaultWithoutSignInUp}
^{nodeSignInUpFeatureStart}
providers: [
{
config: {
thirdPartyId: "twitter",
clients: [{
clientId: "4398792-WXpqVXRiazdRMGNJdEZIa3RVQXc6MTpjaQ",
clientSecret: "BivMbtwmcygbRLNQ0zk45yxvW246tnYnTFFq-LH39NwZMxFpdC"
}]
}
}
]
^{nodeSignInUpFeatureEnd}
}), // initializes signin / sign up features
]
});
```

</TabItem>
<TabItem value="go">


```go
import (
"github.com/supertokens/supertokens-golang/recipe/^{codeImportRecipeName}"
^{goThirdPartyModelsImport}
"github.com/supertokens/supertokens-golang/recipe/^{codeImportRecipeName}/^{goModelName}"
"github.com/supertokens/supertokens-golang/supertokens"
)

func main() {
supertokens.Init(supertokens.TypeInput{
RecipeList: []supertokens.Recipe{
^{codeImportRecipeName}.Init(^{goModelNameForInit}.TypeInput{
^{goRecipeInitDefaultWithoutSignInUp}
^{goSignInUpFeatureStart}
Providers: []tpmodels.ProviderInput{
{
Config: tpmodels.ProviderConfig{
ThirdPartyId: "twitter",
Clients: []tpmodels.ProviderClientConfig{
{
ClientID: "4398792-WXpqVXRiazdRMGNJdEZIa3RVQXc6MTpjaQ",
ClientSecret: "BivMbtwmcygbRLNQ0zk45yxvW246tnYnTFFq-LH39NwZMxFpdC",
},
},
},
},
},
^{goSignInUpFeatureEnd}
}),
},
})
}
```


</TabItem>
<TabItem value="python">


```python
from supertokens_python import init, InputAppInfo
from supertokens_python.recipe import ^{codeImportRecipeName}
from supertokens_python.recipe.thirdparty import ProviderInput, ProviderConfig, ProviderClientConfig

init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
framework='...', # type: ignore
recipe_list=[
^{codeImportRecipeName}.init(
^{pythonRecipeInitDefault}
# highlight-start
^{pythonRecipeInitDefaultWithoutSignInUp}
^{pythonSignInUpFeatureStart}
providers=[
ProviderInput(
config=ProviderConfig(
third_party_id="twitter",
clients=[
ProviderClientConfig(
client_id="4398792-WXpqVXRiazdRMGNJdEZIa3RVQXc6MTpjaQ",
client_secret="BivMbtwmcygbRLNQ0zk45yxvW246tnYnTFFq-LH39NwZMxFpdC",
),
],
),
),
]
^{pythonSignInUpFeatureEnd}
# highlight-end
)
]
)
```


</TabItem>
</BackendSDKTabs>

</TabItem>

<TabItem value="multi">

Call the following function / API to add the third party provider to a specific tenant.

<BackendSDKTabs enableCurl isSubTab={true}>

<TabItem value="nodejs">

```tsx
import Multitenancy from "supertokens-node/recipe/multitenancy";

async function addThirdPartyToTenant() {
let resp = await Multitenancy.createOrUpdateThirdPartyConfig("customer1", {
thirdPartyId: "twitter",
name: "Twitter",
clients: [{
clientId: "4398792-WXpqVXRiazdRMGNJdEZIa3RVQXc6MTpjaQ",
clientSecret: "BivMbtwmcygbRLNQ0zk45yxvW246tnYnTFFq-LH39NwZMxFpdC",
}]
});

if (resp.createdNew) {
// Provider added to customer1
} else {
// Existing provider config overwritten for customer1
}
}
```

</TabItem>
<TabItem value="go">


```go
import (
"github.com/supertokens/supertokens-golang/recipe/multitenancy"
"github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels"
)

func main() {
tenantId := "customer1"

// highlight-start
resp, err := multitenancy.CreateOrUpdateThirdPartyConfig(tenantId, tpmodels.ProviderConfig{
ThirdPartyId: "twitter",
Name: "Twitter",
Clients: []tpmodels.ProviderClientConfig{
{
ClientID: "4398792-WXpqVXRiazdRMGNJdEZIa3RVQXc6MTpjaQ",
ClientSecret: "BivMbtwmcygbRLNQ0zk45yxvW246tnYnTFFq-LH39NwZMxFpdC",
},
},
}, nil)
// highlight-end

if err != nil {
// handle error
}
if resp.OK.CreatedNew {
// Provider added to customer1
} else {
// Existing provider config overwritten for customer1
}
}
```


</TabItem>
<TabItem value="python">

<PythonSyncAsyncSubTabs>
<TabItem value="asyncio">


```python
from supertokens_python.recipe.multitenancy.asyncio import create_or_update_third_party_config
from supertokens_python.recipe.thirdparty.provider import ProviderConfig, ProviderClientConfig

async def some_func():
tenant_id = "customer1"
result = await create_or_update_third_party_config(tenant_id, ProviderConfig(
third_party_id="twitter",
name="Twitter",
clients=[
ProviderClientConfig(
client_id="4398792-WXpqVXRiazdRMGNJdEZIa3RVQXc6MTpjaQ",
client_secret="BivMbtwmcygbRLNQ0zk45yxvW246tnYnTFFq-LH39NwZMxFpdC",
),
],
))

if result.status != "OK":
print("handle error")
elif result.created_new:
print("Provider added to customer1")
else:
print("Existing provider config overwritten for customer1")
```


</TabItem>

<TabItem value="syncio">


```python
from supertokens_python.recipe.multitenancy.syncio import create_or_update_third_party_config
from supertokens_python.recipe.thirdparty.provider import ProviderConfig, ProviderClientConfig

tenant_id = "customer1"
result = create_or_update_third_party_config(tenant_id, ProviderConfig(
third_party_id="twitter",
name="Twitter",
clients=[
ProviderClientConfig(
client_id="4398792-WXpqVXRiazdRMGNJdEZIa3RVQXc6MTpjaQ",
client_secret="BivMbtwmcygbRLNQ0zk45yxvW246tnYnTFFq-LH39NwZMxFpdC",
),
],
))

if result.status != "OK":
print("handle error")
elif result.created_new:
print("Provider added to customer1")
else:
print("Existing provider config overwritten for customer1")
```


</TabItem>
</PythonSyncAsyncSubTabs>

</TabItem>

<TabItem value="curl">

<CoreInjector defaultValue="http://localhost:3567" showTenantId={false}>

```bash
curl --location --request PUT '^{coreInjector_uri_without_quotes}/<TENANT_ID>/recipe/multitenancy/config/thirdparty' \
--header 'api-key: ^{coreInjector_api_key_without_quotes}' \
--header 'Content-Type: application/json' \
--data-raw '{
"config": {
"thirdPartyId": "twitter",
"name": "Twitter",
"clients": [
{
"clientId": "4398792-WXpqVXRiazdRMGNJdEZIa3RVQXc6MTpjaQ",
"clientSecret": "BivMbtwmcygbRLNQ0zk45yxvW246tnYnTFFq-LH39NwZMxFpdC"
}
]
}
}'
```

</CoreInjector>

</TabItem>

</BackendSDKTabs>

</TabItem>

</MultiSingleTenant>

## Active Directory

<MultiSingleTenant>
Expand Down
Loading

0 comments on commit ee1feb2

Please sign in to comment.