Arnab
07/19/2022, 10:41 AMfun contextFn(request: Request): Principal {
val cookie = request.header("Cookie")
val map =
cookie?.split(";")?.associate {
val (first, second) = it.split("=").map { s -> s.replace("\"", "") }
first.trim() to second.trim()
}
?: emptyMap()
// TODO: take the GoogleCsrf and GoogleAccessToken and create a principal based on that
val accessToken = map["GoogleAccessToken"]
val csrf = map["GoogleCsrf"]
return GoogleUser(UUID.randomUUID())
}
Is there something that I should read up on or what am I missing?dave
07/19/2022, 10:43 AMdave
07/19/2022, 10:44 AMArnab
07/19/2022, 10:44 AMArnab
07/19/2022, 10:45 AMAnonymousUser
or something to that accorddave
07/19/2022, 10:48 AMArnab
07/19/2022, 10:51 AMUser
object of sorts and use that as a context for my GraphQL endpoint. I suspect I might need to use this maybe:
https://developers.google.com/identity/sign-in/web/backend-authdave
07/19/2022, 10:54 AMArnab
07/19/2022, 10:57 AMfun contextFn(request: Request): Principal {
val accessToken = request.cookie("GoogleAccessToken")
val csrf = request.cookie("GoogleCsrf")
// TODO decode the access token
return GoogleUser(UUID.randomUUID())
}
fun DataFetchingEnvironment.getPrincipal(): Principal? =
graphQlContext.get<Principal>("principal")
and the contextFn
is supplied like so:
"/graphql" bind graphQL(BaseHandler, ::contextFn, baseExceptionHandler)
So when I am in a query handler, I just need to do this:
fun hello(env: DataFetchingEnvironment) = "Hello ${env.getPrincipal() ?: "anonymous user"}"
dave
07/19/2022, 11:02 AMdave
07/19/2022, 11:04 AM