I'm writing microservices in go and want to migrat...
# general
w
I'm writing microservices in go and want to migrate to using super tokens (self-hosted). What is the "best practice" to authenticate requests on different services? Previously using AWS Cognito which gave me JWKs to validate requests.
r
hey @User it depends on who is querying those micro services - is the frontend querying them or is it one backend microservice to another?
w
Let’s discuss both scenarios as both happen. We have http endpoints coming from react front ends but also grpc and event driven communications too.
r
So from frontend you can query different API domains and share the same user session across all of them as long as all those API domains have the same top level domain. For backend to backend, you can use our JWT recipe to create JWTs and use that for auth. That being said, we will be working on all sorts of m2m auth soon (since using JWTs has its limitations)
w
Thanks for the reply, that is helpful. So the general idea is I'll need to install the supertoken golang sdk on each service, run the
supertokens.Init
with the same config and then use
session.VerifySession
on the endpoints I require? This is in addition to the new service i'm introducing which implements the requires auth endpoints for the frontend sdk. Does that seem generally correct?
r
Yes. Correct!
w
Quick question: what is the suggested way to mock session verification? Basically I’d like to generate access tokens for component tests that’ll pass the session verification middleware’s without having to spin up a local version of core
r
That's unfortunately not optimised for yet 😦
The way we usually recommend testing is by spinning up the core (without a db) and using that to make requests and generate sessions for tests
You can also use the override feature we have to override the session recipe to make fake tokens and do this only during testing
Which SDK are you using? I can write up some sample code here to show you what I mean
w
Go
Yeh some examples might be good. Still new to this library
r
Actually, nvm. Unfortunately there isn't an easy way to mock replies from the core on the SDK level. What you could do is to somehow add http interceptors to network calls like these: https://github.com/supertokens/supertokens-golang/blob/master/supertokens/querier.go#L187 And then mock back replies from the core.
The way we have setup our tests for the SDKs and stuff is that we spin up a core for each test (or a group of tests).
w
Ah ok, thanks 👍
19 Views