-
Notifications
You must be signed in to change notification settings - Fork 562
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
how to use as auth service with hasura #250
Comments
i found the jwt or session of supertokens is dynamic? i don't find the secret as need for jwt sign. how to give one ?becuase hasura need one, here is my hasura docker file: {
"type": "HS256",
"key": "my_long_long_secret",
"claims_namespace": "supertokens",
"claims_format": "json",
"header": { "type": "Authorization" }
} the config tell hasura, use HS256 algo and key is |
yeah, hasura also accept a jws url, but what the url for jws? |
the hasura doc for api auth is https://hasura.io/docs/latest/graphql/core/auth/authentication/jwt.html# |
from now, what i have done and not know how to:
now, supertokens will sign a session, and the jwt payload can be add to it. but what is still not clear to me is how to get a jwt token like this demo |
Hi @chenkaiC4 just a quick heads-up from integrating with Hasura, but because Supertokens has dynamic JWKs, it means that this setup won't work with Hasura. You can disable the rotation of keys, but you'd be dropping out a strong security advantage of super tokens. So far the solution would be using a webhook to take full advantage of super tokens, but the downside is you have to keep a separate server for it, such as hasura-supertokens which I am a maintainer. |
Apart from the webhook method provided by @gusfune , here is another approach that doesn't involve creating a webhook, and allows querying Hasura directly from the frontend. This method is coming soon... First, some terminology:
Implementation details:
createNewSession(userId, jwtPayload) {
let SeJWT = createSeJWT(jwtPayload);
// we then modify the jwtPayload to contain the SeJWT
jwtPayload = {
sejwt: SeJWT
};
let SuAT = createAccessTokenFromSuperTokenCore(userId, jwtPayload);
// attach SuAT to cookies etc...
}
Getting the Hasura token (SeJWT) in the backendapp.post("/some-api", Session.verifySession(), async (req, res) => {
let session = req.session;
let hasuraToken = session.getJWTPayload()["sejwt"];
// query Hasura with hasuraToken
}); Getting the Hasura token on the frontendlet jwtPayload = await Session.getJWTPayloadSecurely();
let hasuraToken = jwtPayload["sejwt"];
// add hasuraToken to authorisation header when querying Hasura
Updating contents of the Hasura token (like the user's role)app.post("/update-role", Session.verifySession(), async (req, res) => {
let session = req.session;
let existingJWTPayload = await session.getJWTPayload();
await session.updateJWTPayload({
...existingJWTPayload,
role: "newRole"
});
});
JWT service:
Customisation options
Advantages:
Disadvantages:
|
Perhaps the core can also offer functionality to sign JWTs (using the api-key as the auth method), and provide a jwks endpoint. |
We have released an implementation of JWT which can be used to integrate with Hasura. Integration docs can be found here: https://supertokens.io/docs/thirdpartyemailpassword/hasura-integration/with-jwt So closing this issue. |
❓ Questions and Help
hi, this project is very nice~
now, i have deploy a standlone Hasura and also Supertokens with dockers.
the Supertokens and Hasura works well. But i want to use Supertokens as auth service for Hasura through jwt or jws。
from docs of Hasura, hasura just work as a graphql api service, and apis are auth by jwt/jws with roles set in payload.
the logic i want to use is:
The text was updated successfully, but these errors were encountered: