// ĠCopyright Ġ 2 0 0 0 - 2 0 2 0 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġorg . jetbrains . plugins . github . authentication Ċ Ċ import Ġcom . intellij . collabor ation . auth . credentials . Credentials Ċ import Ġcom . intellij . collabor ation . auth . credentials . Simple Credentials Ċ import Ġcom . intellij . collabor ation . auth . services . OAuth Service Base Ċ import Ġcom . intellij . openapi . components . Service Ċ import Ġcom . intellij . openapi . components . service Ċ import Ġcom . intellij . util . Url Ċ import Ġcom . intellij . util . Urls . new From Encoded Ċ import Ġcom . intellij . util . io . Digest Util . random Token Ċ import Ġcom . intellij . util . io . Digest Util . sha 2 5 6 Ċ import Ġorg . jetbrains . ide . BuiltIn Server Manager Ċ import Ġorg . jetbrains . ide . Rest Service Ċ import Ġjava . net . http . HttpHeaders Ċ import Ġjava . util .* Ċ Ċ @ Service Ċ internal Ġclass ĠG HO Auth Service Ġ: ĠOAuth Service Base < Credentials >() Ġ{ ĊĠ Ġprivate Ġval Ġcode Verifier : ĠString Ġ= Ġrandom Token () ĊĠ Ġprivate Ġval Ġcode Challenge : ĠString Ġget () Ġ= ĠBase 6 4 . get Encoder (). encode ToString ( sha 2 5 6 (). digest ( code Verifier . toByteArray ())) ĊĠ Ġprivate Ġval Ġport : ĠInt Ġget () Ġ= ĠBuilt In Server Manager . getInstance (). port ĊĊĠ Ġoverride Ġval Ġname : ĠString Ġget () Ġ= Ġ" github / oauth " ĊĠ Ġoverride Ġval Ġauthorization Code Url : ĠUrl Ġget () Ġ= Ġnew From Encoded (" http :// 1 2 7 . 0 . 0 . 1 :$ port /${ Rest Service . PREFIX }/ $ name / authorization _ code ") ĊĠ Ġoverride Ġval Ġsuccess Redirect Url : ĠUrl Ġget () Ġ= ĠSERVICE _ URL . resolve (" complete ") ĊĠ Ġoverride Ġval Ġerror Redirect Url : ĠUrl Ġget () Ġ= ĠSERVICE _ URL . resolve (" error ") ĊĊĠ Ġoverride Ġfun Ġre voke Token ( token : ĠString ) Ġ{ ĊĠĠĠ ĠTODO (" Not Ġyet Ġimplemented ") ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġget Auth Url With Parameters (): ĠUrl Ġ= ĠAUTHOR IZE _ URL . add Parameters ( map Of ( ĊĠĠĠ Ġ" code _ challenge " Ġto Ġcode Challenge , ĊĠĠĠ Ġ" callback _ url " Ġto Ġauthorization Code Url . to External Form () ĊĠ Ġ)) ĊĊĠ Ġoverride Ġfun Ġget Credentials ( response Body : ĠString , Ġresponse Headers : ĠHttp Headers ): ĠCredentials Ġ= ĊĠĠĠ ĠSimple Credentials ( response Headers . first Value (" X - OAuth - Token "). get ()) ĊĊĠ Ġoverride Ġfun ĠgetToken Url With Parameters ( code : ĠString ): ĠUrl Ġ= ĠACCESS _ TOKEN _ URL . add Parameters ( map Of ( ĊĠĠĠ Ġ" code " Ġto Ġcode , ĊĠĠĠ Ġ" code _ verifier " Ġto Ġcode Verifier ĊĠ Ġ)) ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġval Ġinstance : ĠG HO Auth Service ĊĠĠĠĠĠ Ġget () Ġ= Ġservice () ĊĊĠĠĠ Ġprivate Ġval ĠSERVICE _ URL : ĠUrl Ġ= Ġnew From Encoded (" https :// account . jetbrains . com / github / oauth / intellij ") ĊĊĠĠĠ Ġval ĠAUTHOR IZE _ URL : ĠUrl ĊĠĠĠĠĠ Ġget () Ġ= ĠSERVICE _ URL . resolve (" authorize ") ĊĠĠĠ Ġval ĠACCESS _ TOKEN _ URL : ĠUrl ĊĠĠĠĠĠ Ġget () Ġ= ĠSERVICE _ URL . resolve (" access _ token ") ĊĠ Ġ} Ċ } Ċ