Skip to content

Commit

Permalink
fixes docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Nov 28, 2023
2 parents b5d64a9 + a56d486 commit 7ae2ac8
Show file tree
Hide file tree
Showing 29 changed files with 637 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ This feature is only available for SDKs versions:

This hook can be used to intercept all outgoing requests from the backend SDK to the core. The request can be captured and modified before it is sent to the core.

The hook is useful for debugging purposes and for adding custom headers to the request.

The `networkInterceptor` function takes an HTTP request and returns the same request object or a modified request object.
Users can modify the HTTP method, query params, headers and body of the request.

## Example Use
Expand All @@ -32,31 +29,32 @@ Users can modify the HTTP method, query params, headers and body of the request.
<TabItem value="nodejs">

```tsx
import Session from "supertokens-node/recipe/session";
import HttpRequest from "supertokens-node/types";
import { HttpRequest } from "supertokens-node/types";
import SuperTokens from "supertokens-node";

SuperTokens.init({
supertokens: {
connectionURI: "https://dev-1c55f9c124d311ee9fa15fb58a3e1b69-us-east-1.aws.supertokens.io:3568/appid-<APP_ID>",
apiKey: "9-o4QBtuWy65L1iZskNiug1DRFKWh6",
// highlight-start
networkInterceptor: (request: HttpRequest, userContext: any) => {
console.log("http request to core: ", request)
// this can also be used to return a modified request object.
return request;
},
// highlight-end
},
appInfo: {
apiDomain: "api.supertokens.io",
appName: "SuperTokens",
websiteDomain: "supertokens.io",
},
recipeList: [
Session.init()
],
});
supertokens: {
connectionURI: "...",
apiKey: "...",
// highlight-start
networkInterceptor: (request: HttpRequest, userContext: any) => {
console.log("http request to core: ", request)
// this can also be used to return a modified request object.
return request;
},
// highlight-end
},
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "...",
},
recipeList: [
// ...
],
});
```

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

Expand All @@ -65,15 +63,14 @@ import (
"log"
"net/http"

"github.com/supertokens/supertokens-golang/recipe/session"
"github.com/supertokens/supertokens-golang/supertokens"
)

func main() {
supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "https://dev-1c55f9c124d311ee9fa15fb58a3e1b69-us-east-1.aws.supertokens.io:3568/appid-<APP_ID>",
APIKey: "9-o4QBtuWy65L1iZskNiug1DRFKWh6",
ConnectionURI: "...",
APIKey: "...",
// highlight-start
NetworkInterceptor: func(request *http.Request, context supertokens.UserContext) *http.Request {
log.Print("http request to core: %+v", request)
Expand All @@ -82,54 +79,53 @@ supertokens.Init(supertokens.TypeInput{
// highlight-end
},
AppInfo: supertokens.AppInfo{
AppName: "SuperTokens",
APIDomain: "api.supertokens.io",
WebsiteDomain: "supertokens.io",
},
RecipeList: []supertokens.Recipe{
session.Init(nil),
AppName: "...",
APIDomain: "...",
WebsiteDomain: "...",
},
RecipeList: []supertokens.Recipe{/*...*/},
})
}
```

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

```python
from typing import Dict, Any, Optional, str

from typing import Dict, Any, Optional
from supertokens_python import init, InputAppInfo, SupertokensConfig
from supertokens_python.recipe import session

# highlight-start
def intercept(
url: str,
method: str,
headers: Dict[str, Any],
params: Optional[Dict[str, Any]],
body: Optional[Dict[str, Any]],
_: Optional[Dict[str, Any]], # user_context
):
print("http request to core: ", url, method, headers, params, body)
return url, method, headers, params, body
url: str,
method: str,
headers: Dict[str, Any],
params: Optional[Dict[str, Any]],
body: Optional[Dict[str, Any]],
user_context: Optional[Dict[str, Any]],
):
print("http request to core: ", url, method, headers, params, body)
return url, method, headers, params, body
# highlight-end

init(
app_info=InputAppInfo(
app_name="SuperTokens",
api_domain="api.supertokens.io",
website_domain="supertokens.io",
app_name="...",
api_domain="...",
website_domain="...",
),
supertokens_config=SupertokensConfig(
connection_uri="https://dev-1c55f9c124d311ee9fa15fb58a3e1b69-us-east-1.aws.supertokens.io:3568/appid-<APP_ID>",
api_key="9-o4QBtuWy65L1iZskNiug1DRFKWh6",
connection_uri="...",
api_key="...",
# highlight-next-line
network_interceptor=intercept,
),
framework='django',
framework="django", # works with other frameworks as well
recipe_list=[
session.init(),
# ...
],
mode='asgi'
)
```

</TabItem>
</BackendSDKTabs>
2 changes: 1 addition & 1 deletion v2/emailpassword/advanced-customizations/user-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ class EmptySession(session.SessionContainer):
async def get_expiry(self, user_context: Union[Dict[str, Any], None] = None) -> int:
return -1

async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod):
async def attach_to_request_response(self, request: BaseRequest, transfer_method: TokenTransferMethod, user_context: Union[Dict[str, Any], None] = None):
pass

async def assert_claims(
Expand Down
40 changes: 37 additions & 3 deletions v2/emailpassword/common-customizations/multiple-clients.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,43 @@ func main() {
</TabItem>
<TabItem value="python">

:::note
Coming Soon
:::
```python
from supertokens_python import init, InputAppInfo, SupertokensConfig
from supertokens_python.framework.request import BaseRequest
from typing import Optional, Dict, Any


# highlight-start
def get_origin(request: Optional[BaseRequest], user_context: Dict[str, Any]) -> str:
if request is not None:
origin = request.get_header("origin")
if origin is None:
# this means the client is in an iframe, it's a mobile app, or
# there is a privacy setting on the frontend which doesn't send
# the origin
pass
else:
if origin == "https://test.example.com":
# query from the test site
return "https://test.example.com"
elif origin == "http://localhost:3000":
# query from local development
return "http://localhost:3000"

# in case the origin is unknown or not set, we return a default
# value which will be used for this request.
return "https://test.example.com"
# highlight-end

init(
app_info=InputAppInfo(app_name="...", api_domain="...", origin=get_origin),
supertokens_config=SupertokensConfig(connection_uri="...", api_key="..."),
framework="fastapi", # works with other frameworks as well.
recipe_list=[
# ...
],
)
```

</TabItem>
</BackendSDKTabs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ If you want session verifications to fail immediately after the session has revo

This feature works by passing the `checkDatabase` option when verifying the session as shown below.

:::caution
For managed service users, please check [our rate limit policy](../../rate-limits) before implementing this feature. If you suspect that you will breach the free limit you can:
- [Email us](mailto:[email protected]) to increase your rate limit.
- Use the `checkDatabase` flag only on certain important APIs. For example, omit using it in any `GET` API as those are not state changing.
- Implement your own method for keeping track of revoked access tokens by using a cache like Redis.
:::

## Using the `verifySession` middleware

<BackendSDKTabs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ This feature is only available for SDKs versions:

This hook can be used to intercept all outgoing requests from the backend SDK to the core. The request can be captured and modified before it is sent to the core.

The hook is useful for debugging purposes and for adding custom headers to the request.

The `networkInterceptor` function takes an HTTP request and returns the same request object or a modified request object.
Users can modify the HTTP method, query params, headers and body of the request.

## Example Use
Expand All @@ -32,31 +29,32 @@ Users can modify the HTTP method, query params, headers and body of the request.
<TabItem value="nodejs">

```tsx
import Session from "supertokens-node/recipe/session";
import HttpRequest from "supertokens-node/types";
import { HttpRequest } from "supertokens-node/types";
import SuperTokens from "supertokens-node";

SuperTokens.init({
supertokens: {
connectionURI: "https://dev-1c55f9c124d311ee9fa15fb58a3e1b69-us-east-1.aws.supertokens.io:3568/appid-<APP_ID>",
apiKey: "9-o4QBtuWy65L1iZskNiug1DRFKWh6",
// highlight-start
networkInterceptor: (request: HttpRequest, userContext: any) => {
console.log("http request to core: ", request)
// this can also be used to return a modified request object.
return request;
},
// highlight-end
},
appInfo: {
apiDomain: "api.supertokens.io",
appName: "SuperTokens",
websiteDomain: "supertokens.io",
},
recipeList: [
Session.init()
],
});
supertokens: {
connectionURI: "...",
apiKey: "...",
// highlight-start
networkInterceptor: (request: HttpRequest, userContext: any) => {
console.log("http request to core: ", request)
// this can also be used to return a modified request object.
return request;
},
// highlight-end
},
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "...",
},
recipeList: [
// ...
],
});
```

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

Expand All @@ -65,15 +63,14 @@ import (
"log"
"net/http"

"github.com/supertokens/supertokens-golang/recipe/session"
"github.com/supertokens/supertokens-golang/supertokens"
)

func main() {
supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "https://dev-1c55f9c124d311ee9fa15fb58a3e1b69-us-east-1.aws.supertokens.io:3568/appid-<APP_ID>",
APIKey: "9-o4QBtuWy65L1iZskNiug1DRFKWh6",
ConnectionURI: "...",
APIKey: "...",
// highlight-start
NetworkInterceptor: func(request *http.Request, context supertokens.UserContext) *http.Request {
log.Print("http request to core: %+v", request)
Expand All @@ -82,54 +79,53 @@ supertokens.Init(supertokens.TypeInput{
// highlight-end
},
AppInfo: supertokens.AppInfo{
AppName: "SuperTokens",
APIDomain: "api.supertokens.io",
WebsiteDomain: "supertokens.io",
},
RecipeList: []supertokens.Recipe{
session.Init(nil),
AppName: "...",
APIDomain: "...",
WebsiteDomain: "...",
},
RecipeList: []supertokens.Recipe{/*...*/},
})
}
```

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

```python
from typing import Dict, Any, Optional, str

from typing import Dict, Any, Optional
from supertokens_python import init, InputAppInfo, SupertokensConfig
from supertokens_python.recipe import session

# highlight-start
def intercept(
url: str,
method: str,
headers: Dict[str, Any],
params: Optional[Dict[str, Any]],
body: Optional[Dict[str, Any]],
_: Optional[Dict[str, Any]], # user_context
):
print("http request to core: ", url, method, headers, params, body)
return url, method, headers, params, body
url: str,
method: str,
headers: Dict[str, Any],
params: Optional[Dict[str, Any]],
body: Optional[Dict[str, Any]],
user_context: Optional[Dict[str, Any]],
):
print("http request to core: ", url, method, headers, params, body)
return url, method, headers, params, body
# highlight-end

init(
app_info=InputAppInfo(
app_name="SuperTokens",
api_domain="api.supertokens.io",
website_domain="supertokens.io",
app_name="...",
api_domain="...",
website_domain="...",
),
supertokens_config=SupertokensConfig(
connection_uri="https://dev-1c55f9c124d311ee9fa15fb58a3e1b69-us-east-1.aws.supertokens.io:3568/appid-<APP_ID>",
api_key="9-o4QBtuWy65L1iZskNiug1DRFKWh6",
connection_uri="...",
api_key="...",
# highlight-next-line
network_interceptor=intercept,
),
framework='django',
framework="django", # works with other frameworks as well
recipe_list=[
session.init(),
# ...
],
mode='asgi'
)
```

</TabItem>
</BackendSDKTabs>
Loading

0 comments on commit 7ae2ac8

Please sign in to comment.