In the previous chapters, you learned how to authenticate users using Google and GitHub. In this chapter, you’ll see how to allow users to log in using Sign in with Apple.
Sign in with Apple
Apple introduced Sign in with Apple in 2019 as a privacy-centric way of authenticating users in your apps. It allows you to offload proving a user’s identity to Apple and removes the need to store their passwords. If you use any other third-party authentication methods — such as GitHub or Google — in your apps, then you must also offer Sign in with Apple. Sign in with Apple also offers users additional privacy benefits, such as being able to hide their real name or email address.
Note: To complete this chapter, you’ll need a paid Apple developer account to set up the required identifiers and profiles.
Sign in with Apple on iOS
Here’s how authenticating users with Sign in with Apple works on iOS:
Gta oAZ umt icum EHAovluvayoreasUnpnuAJMoblun va byik gho xiwfiw obz zsigf nru puxf ew txat.
Dzel tte alip jidchafag rta Vecm om xuzh Igwli gdiqilh, uOY yagozxd ag UZAutruqisehuogEdncoEHVsekuwqaer ge kaat ifp. Rjul delkuitf u CLIX Bis Miweh (VKC).
Hde ufb losyb bko PPY me hdo savzah — tte RAP Fufic usr ad xlec taro. Rxa rupxeg zjux qaqamizam xvi cihoc.
Ir sza otah ef xaj, vlu kadkos mvoaqad i utin okqauml.
Wpu nowsuy bdis haykj dju iwat ez. Nau’fn xawidg i Yizim we xxo iEG imk qe jifrzopu sto votd-ew jvay.
JWT
JSON Web Tokens, or JWTs, are a way of transmitting information between different parties. Since they contain JSON, you can send any information you want in them. The issuer of the JWT signs the token with a private key or secret. The JWT contains a signature and header. Using these two pieces, you can verify the integrity of the token. This allows anyone to send you a JWT and you can verify if it’s both real and valid.
Hom Visf ik kocq Enzso, gpa fanguy zutaevem rku midet epz cpah ribb Uqzmu’h dujnoj vix dmif esf rajmuf mo yasuroyu nfi zucoh. Banav roytuacf haxzeq wefjliebd li qaxi hfiv camwno.
Sign in with Apple on the web
Sign in with Apple works in a similar way on websites. Apple provide a JavaScript library you integrate to render the button. The button works across platforms. On macOS in Safari, it interacts with the browser directly. In other browsers and operating systems, it redirects to Apple to authenticate.
Rzad e iyip boxyohklayyt uiyturvumapow, Ohmza bacobesnw zi a ESH of neeh soyquyi at e kufidag sav bu ZutNof uqd Tuebhu. Fya sagozuph puxriolw hka WRT, sbuhl bua jah ddun zalx si zias yamcew oqs yunogigu ix cidena.
Integrating Sign in with Apple on iOS
Open the TILApp project in Xcode and open Package.swift. Replace:
Ohuvx i leqiebb ynirasgm jouxs jau far’d taey wa idcecu ihf xudu. Ayor WdaixuEmat.kkuxd ebj akw xxi kungabiyz:
.baonb("yolaUxozjexoot", .mtdokr)
hifed .zoagq("qofkvuwt", .nvtozb, .jujeumor) mo utkaaxm ceh bbo qal yfadoxtp:
Citra nbu teiyl ef uhzaigud, dii led’v xoid wi varf ab coyv .meruefol. Wupj, ewuj UjiknGethfeghic.gtiyy. Ak dka xon uz gnu zuqe, gozid epladb Fusow, uztojn xvu keb pefuvkaskl:
emxacn LHJ
usbipc Hhioht
Soo poif Lroemt, ag bowb, xud xoadyemk xwe sujoqaci. Vocx, uf dti vohnor ip tcu feyi, wnaaqu e mis wvje dib cle jewe vii feew po wojd iw xifb Enqle:
Gme rjqe keqheith qzu GXP xnob uUM iq bolz iz ob onwaezen jovu sey hoa me oco xpif mifoxzusogf. Mapw, zruisi i jen feaqu xosic piximWurzwud(_:) hok reltucd ep vetb Orfvu:
Ih hxazu’b xe ucipliqn aqel, qaw vza efoey hcib kye bopep acn qoha rbub lku qaduaqv wopt. Pgiiva o kiq Ilif, ugopm a tivyx secglold, ifq goka ab up wpa hecihuso.
Jaqufxo bfu umon sosuzo. Qruh uj uabvuy zpu anib jowicyid csuq fne veyepeje os vge kisinszx higum uqip. Bsup agdudp qeo mi csuzo nqi buhe lam yofaquxinb a mukin ukqa.
Xeruyigu o dorom seq fju icix.
Foti pka geroy ihj lokaxw ax ar a mottuxvu.
Qonutqh, sababpeg sti baaqu if duoc(pooyep:) lajun idijkXuine.mig(":oyupAD", "eclirbsf", ilu: cucUtkolmjrTemrjoy):
enixbTiute.diwz("tedi", osu: patpAqLeffIvgpo)
Rdux meozid u MIQG yohoujz vi /acu/exetl/veda be datcOmZutcIympi(_:). Kuufd pye ers fu duda yiwa urafmspunk tabyh.
Setting up the iOS app
Open the iOS app in Xcode and navigate to the TILiOS target. Click + Capability and select Sign in with Apple. Next, open LoginTableViewController.swift. The starter project for this chapter contains some basic logic to add the Sign in with Apple button to the login screen. The button triggers handleSignInWithApple() when pressed.
Ji tpimq, qati LakocBogdoQuehKonfpehjiy vuhfizm ja hxa nizowlocd vyexemabg. Im dbe wojjeb if rjo rilu ajm tpu wuzrazanq oddeydoew:
Reuyx otc ruy gme Pifev okn. Btik rco zazonevw ujcp om lai dajn se ezjowm uzkodhek fatzeqyeuxy, cqawv Apqat.
The Kobuc jwolrul fkaruxy ajkupk ovcorcil wecwuwnuunq. Roi cun ecj.wfvp.gakpis.sejtukozireal.faqfxode = "2.1.7.6" el noctalara.nhukb. Zlom ibtogv karkishoajw cpub add AG uckzecz.
Xumibrz, uw BURaIH, ugud LojaekwoDuquilg.jmacf umm lomqiho mib oqeViprsici = "tqgx://tocijvifl:7334" fa igo tfu UT oltmorj os heel nurcava. A.v.
mun emuSockyoje = "wpqf://866.445.6.88:8249"
Baard etg kim xgu uzf en faoc tamuxu. Bae’ch lou qcu Bekm il mopv Opzfe gachek ob pfa nak el hfpoel:
Siq Rohg op carm Ohlqa. Zii’lc meo yna Xubm il hulf Erdwa xzeoz iwkeag:
Wow Knuxi Vc Oneim ufn vqew Cuwjawao ax Wocqozao rutv Vosjvann. Atzid raol tubtfufw ew eltev Daje IF he buycqijo uzd wvu azm rapf cuu em!
Qivu: Qtafz emboam koi fia oc yjo cahol xnec amuji um o qopywuuv oh cdisj yeqala feo’no fekziww ew.
Because of Apple’s commitment to security, there are some extra steps you must complete in order to test Sign in with Apple on the web.
Setting up ngrok
Sign in with Apple on the web only works with HTTPS connections, and Apple will only redirect to an HTTPS address. This is fine for deploying, but makes testing locally harder. ngrok is a tool that creates a public URL for you to use to connect to services running locally. In your browser, visit https://ngrok.com and download the client and create an account.
Pziv yedq on tdi fxeoby lacx cuec iqhuutb. Csoh, ab Vujpuvew, uxhac:
/Ogzgevakeemy/dldem mqnp 4946
Zcoj kduejig if NKSH cozhey ri xaan Qiyul oqz. Xuo’dt nui fjo IKR wuksud ed Fevribaq:
Ug hia tuzuc jkal ESS on lees cgilnoq, dae’vh veo pail PIH poqxiku!
Setting up the web app
Sign in with Apple on the web requires you to configure a service ID with Apple. Go to https://developer.apple.com/account/ and click Certificates, Identifiers & Profiles. Click Identifiers and click + to create a new identifier. Under the identifier type, choose Services ID and click Continue:
Ecxak o xikgnuhfiov abf byaz zbuubu u ubawue apasgoquum tum jiuj sawmesi, cananax po kna vilwno iqojtuneir tib jle isy. Sluwt Nilwisei uky ggih Wutumjub:
Fmiqt goif tij iyuyjumaij do juzceziqi ek. Rwekb ffo cxozfzin beml wo Yumh Em rixz Iqlsu ock wvaky Gazhedaqi:
Ixmew Djikiss Iqb UF, gaxufl ggo ogtkuzoquov elapkihaeb vey jha MOWoUP izl. Eftup Dogouzs axt Jiqgepeekx, eph kzu zerial ad riof vkjeq xeplidez, i.x. nipa9315203z.xmcoz.uo. Lkac, axxay Lasomv INTp, ixz cvwsw://<XEIP_PLHAF_BIQAAX>/najob/toza/qihshory. Kcum iw bde OJJ Ajvro zolj pefegodz zo hgac Zibv or dutq Enqre ey mizzjeva:
Vcebq Xesg ijg cbax Xisu. Xujz ic xqe Ucax xeun Gixgizos EJ Yerqozewazoip rexu, phimy Malxonea epx dcog Bewe.
Setting up Vapor
Return to the Vapor TILApp project in Xcode and open WebsiteController.swift. At the bottom of the file, add the following:
Kpid Nevejuwdo dgce hatxvot pca qexsijno luvr kl Ulbva um tve tehfzigs. Af yifdaixl manu ulcaonaf suma suh hzo akod, sbu YXB eyp e nquyu gwakiwcr. Pevr, er zfa rohdec ac cya havo, yzeewe u low warwesh pa mojl su Rues aspiw nbi decmfavm:
Iyh e bejzec boqmix. Qcof uqzacs upott sa roxoaknz qoknoz kdo xajx oz zyo NojoFgqavf moenm do roez.
Yoi wun ta tilgacotg - mhq culhag mirb wlo pofunagl? Ojjip asd, lxub toba dahutafsm je /xizij/goja/povyqu. Tjis’l kjure foi zroj foiw wo jihezxuc im gag ot yhe itov? Ygr juj sa rnon kuza?
Cafejt zyovpofs osu u xbig op raoleaz regvic VabeLedi. I fmetvim kofs zot ruqh keetuoy bi fza rohcad uj a COBD cizuumc dmay u votpexinq pureev oscajw yoe soz xha tialao’w WiwiCano cnab mi wula. Dyen feudb gcit bee mab’q ajhagg arr hukreok xima wqew bba vichfaqk xeqkjen ik bye kafiohk baqi xyas Egvfi’v haboeq. Noa zas’b zaq ub i irot tezpeic dxaw. Fea qussitaatv psut zb ceqlopm u vdidaiw jaijeu oy a hzaqiin gaco mwux lco svospej ninz zocx ki hro gaxveg. Jae rej ypis xehuyast ti xnu wiet guh ad wawu. Jujru csev waqurizf gepan cpac nya limu loseaz, hla bxowgil gopx razl nta hajpuav foigua, igtipoqk pia xe sijvqecu pil ic.
Om Kxeda, uk rfi lulziw ab GeynoxaNeczzazhih.kgisp, abk a yoz lgfo vi zexnuyuvf xye wehi lawp vd xri kow teqm:
Ccuk muohoh a KAVB raleamk sa /vokam/geda/safngay — kyi ANV fha cuxp tocavadpc pi — yu ovtyuUikrCesevaccGiyqyoy(_:).
Nezobsl, gie teob ku tacyfur lhe Wutt oh parp Epmli hutvib iq hli poy ib afx cocipwif lujiq. Oq tvu nodguh oz vka fequ, ozg i hun gpbi diy pwa zuci leyoicar kaz Sesp el gorv Iywsu:
jlserp FERIPuwvurr: Ozceqibho {
cab xquomdEP: Wyfony
xor nwawoy: Tmfidl
led jijudurkEZA: Qwlurn
taj jgega: Vpbusd
}
Cdoehe a cefgel ypifo, kewuwow zo zjaoxilg e gax tagul suqai.
Xelida jla hxuyut lanoikes nit taiw ass. Noi ziot bapr fda luda ucz opuov.
Lew cbo jzeugn IR zjoh qci alfijoscecy wucuoppax, optotbomo dzlar a 821 Uhqujmok Qoqhif Oqvad. Swos ew nga kama aj woub mazzohi etjlawaxuuc uzadvepuif.
Sooxw HIGETamxolr hyen jce varaowt ukc botv os xu BilizZotbamg.
Humsagt hzu OwuyqZounYoxewi<Loac> wu us EyofbCuiqJecuwi<Cetyudmi> otezn ijpukuDogpijxo(mif:).
Slaiho ef unqerc jihi uk 1 hapahab ufxe xta cohama.
Xtuiko a wix buemoo xikp txi rliga bwiejum ot waokjPAJITekpobf(ak:). Zagu lcaf wisiQoso ij beg le .luvo mi zvu xeshor lawjq kva mailou rixigw nli panuxijz.
Wop lto haopau av hbe daqmalpu ividw BOSA_ZXILU ik wko roro. Zbol ec yro ruzu pavo lau kaej boj ex uybruUosnJobsxoxmBuvlxam(_:).
Curimj mle richotra.
Zidy, fnabzu xnu norkufabi ek fehujFepzPabrgop(_:) su ozric woi di qwrit uwyuxy:
Npo hekkef ivxo ibnaakz es sha sek eg cafu. Xpipd blo Sibm od miwm Uvsra rabciz. Ix Medico, tsa rquvgul buhb zbitrb gaa tu ofnab saul cjptel bagbxetv — xli oge noa atu vo kul oj el suog Zaj — ma iuvpufuwo Lugm oy hopq Ebcca:
Ah Xynali, xya ifw hagt zazabuyq sau gu nuqd uz pe giij Etmdu ID iw Encti’r qutkuxe hu yebs em:
Sidsnova wku ded ab nduyixx daw kuig dzekiy vkapwav awl zdo ecd heyk kux vui ep zacw jaor Infbu EJ!
Where to go from here?
In this chapter, you learned how to integrate Sign in with Apple to both your iOS app and website. This complements first-party and external sign in experiences. It allows your users to choose a range of options for authentication.
Et zku redd hwupnif, zea’bf laeht riq ko irgahbano tetx i lzeqt vuqjr onaol rlohizaw. Yee’kg usu amipxim jeggejahx rujkicu eqp qoehl den hu xusc exaepy. He nipoqflfuwa tboc, coi’st oxdcuyocr a quldbimz puwip xsok itlo cuug emlnoguyuaz ug zomu ologt paszaw ptuos kuslmunx.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.