package Ġjp . gree . tech con . server . service Ċ Ċ import Ġcom . auth 0 . j wk . J wk Provider Builder Ċ import Ġio . ktor . auth . Authentication Ċ import Ġio . ktor . auth . Authentication Context Ċ import Ġio . ktor . auth . jwt . JWT Principal Ċ import Ġio . ktor . auth . jwt . jwt Ċ import Ġjava . net . URL Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ // ĠS EE : Ġhttps :// cloud . google . com / iam / docs / creating - man aging - service - account - keys # creating _ service _ account _ keys Ċ const Ġval ĠJ W KS _ URL Ġ= Ġ" https :// www . googleapis . com / service _ accounts / v 1 / j wk / secure token @ system . g service account . com " Ċ Ċ class ĠTech con App Authentication Configuration () Ġ{ ĊĠĠĠ Ġlateinit Ġvar Ġg cp Project : ĠString Ċ } Ċ Ċ fun ĠAuthentication . Configuration . tech con ( ĊĠĠĠ Ġconfigure : ĠTech con App Authentication Configuration . () Ġ-> ĠUnit Ċ ) Ġ{ ĊĠĠĠ Ġval Ġconfig Ġ= ĠTech con App Authentication Configuration (). apply ( configure ) ĊĠĠĠ Ġval Ġj wk Issuer Ġ= Ġ" https :// secure token . google . com /${ config . gcp Project }" ĊĠĠĠ Ġval Ġjwt Audience Ġ= Ġconfig . gcp Project ĊĠĠĠ Ġval Ġj wk Provider Ġ= ĠJ wk Provider Builder ( URL ( JW KS _ URL )) ĊĠĠĠĠĠĠĠ Ġ. cached ( 1 0 , Ġ 2 4 , ĠTimeUnit . HOUR S ) ĊĠĠĠĠĠĠĠ Ġ. rate Limit ed ( 1 0 , Ġ 1 , ĠTimeUnit . MIN UTES ) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ Ġjwt Ġ{ ĊĠĠĠĠĠĠĠ Ġverifier ( j wk Provider , Ġj wk Issuer ) ĊĠĠĠĠĠĠĠ Ġvalidate Ġ{ Ġcredentials Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( credentials . payload . audience . contains ( jwt Audience )) ĠJWT Principal ( credentials . payload ) Ġelse Ġnull ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ fun ĠAuthentication Context . firebase Uid () Ġ= Ġthis . principal < JWT Principal >() ?. payload ?. subject