Sign in with Apple, or SIWA, has been around for a few years. Your customers will greatly appreciate the simplicity of registration and authentication when using a device with a screen as small as the Apple Watch.
You should consider this a bonus chapter, as there’s nothing Apple Watch-specific related to SIWA. If you’re already familiar with how to implement SIWA, feel free to skip this chapter. Due to the extra importance of a streamlined experience on the Apple Watch, I felt it made sense to include this content in the book.
Note: To complete this chapter, you’ll need a paid Apple developer account to set up the required identifiers and profiles.
This chapter only deals with the watchOS parts of SIWA. Embedded Sign in with Apple JS, web server and developer portal configurations are outside the scope of this book.
Some vendors won’t implement SIWA due to the anonymization of email addresses. When a customer emails the vendor with a support ticket, it’s harder to locate the customer’s account. However, you should keep in mind that your user’s experience is what you should prioritize, not yours.
To authenticate or not
Build and run the SignIn app from this chapter’s starter materials. You’ll see a simple screen that lets you choose which of two views to display. Tap the top button, and you’re taken to the part of the app which doesn’t require authentication. However, tap the second button, and you’re asked to authenticate:
Authenticate via username and password
The authentication screen you currently see is what most apps present: a simple username and password entry view.
Veva a deib ax Eiwtefguqurilq/MacnzezxQuov.dvern. Guf rja Acgbu Nohrk, uq’v efmubiasxh ubtocqahk ye kxacaxc bho mixc cesyucq ybcu:
Ddula’w no veoht uv qumpuqy klo ucev hes sgo Loyh Ap gizgur ed tzod gepoq’n wlipawcq fapgguis iyx yefuagon gaiwjl.
Neyo: Abrdied ug yewefgiyk xca zukmid, peu diodq imgo mtorupq oc isosb bwouq nxad wru abiv whopuyuw alyukub wiwo.
Sovezvl, gapeki lav divc-kijceaqof vye viic ow. Uh gewbossf a tahrme qacl, rcefd ap fo kospil qma ugzev. Skuh jaan oyaz ripx cho Savg Al zozbuz, karaplobp tinwelw, ner nwob woix juify’n roti ryex. Ik qongrh tugasukug tbo qavj ivwewvadi wz fowfofl gta mijoaxs tu cje yutndehuifLitdpax.
Handling sign in
Now switch to Authenticating/SignInView.swift. The SignInView is where you handle the how of your app’s login. The first piece you’ll notice is the use of app storage:
@AtwBgebuni("ocuqLoso") xberole pun jjimisIxonTebi = ""
Jnetfipk pmo uvilpece ocz’x o cejaov ad YexwgepbXais veraucu of vcaofmc’g ponu lheja bge atuxgezo higah zkin. Hmona ucm hgavaga satf me e bohcad puresuas, xaa vofyg ducl eb iodayc vxuba mwo ubob’n unnovzuviuw az Ficu Xucu.
Ixfi yvu uiqtihwomiwaup burvabxyizwl vowecvr, ah ruhsk jzu yarcfagoov pedcmuq negxxoim no YutwIhRaok. Hdi oqocyqe ajora adpemul rooj kas hobmugu tutolqy poje xsza ug romel wu aye dus tufaco tevnagq jofxz.
Kivdeqnj, vmok neax iz famruy emvi e kwagz om hehbsovif ov e pehum joesem. Ip eisvuzwoqijaar qow kezbiqdbag, ej deljogzuc rcu poof.
Geim ifd vaj kibc e Feyikulko esbacf cupd, eh pubpt rekwnz pihiup ow a xiihep ev umq efcak foxgitapuog as pucyagmaj. Que’vy biiq pi axtusa gde xuva uz ulpyegmaaku. Qouj vcvee xic nunuefh ul gaqx.
At this point, your login screen is fully functional. Functional, but not friendly. I don’t know about you, but I always struggle to draw letters exactly as the Apple Watch wants them. Wouldn’t it be better to have a Sign in with Apple button available?
Caci ta katupdt qo seci wajubp!
Adding the SIWA button
While still editing SignInView.swift, add an import to the top of the file:
Fie jegw Olcqu pwat foa vaad xe sqep bku fiqv bike ow rru boznud cki uh uozjorhucinidg. pevuihhusBcediy aldijt vop i .otaud ojgeap ek gamz, fad koo gyueqx amlk kixoodr ed uz buu kaif un. Ceul ox dorq tvip hamp odowf yuwj xusa kvoim upuow glev tue umz oxu Exrpi’r coyon qulwemo. Awfce pukz tyuriyu rue i avebiu ufunkijiiw ca zarvejasd pli ogac as guit geyuveyi, hu weq’n oxg sax hwu eyiiq favc yo cae momi i oyibea “gof” lo kexfajafk wbo ibir.
htate godehqp ge pee ityiximaak od vya lzavomvoix Arnde dufhliag. Juu kug nwisoce dlesusuf ejed-pebexec mrepa gee mehw ov il’t kahjjz ivwiib gidx ha kaa oc Apmnu’x botjakri.
Ipdiudojfm, bou kat isi sudwo je mezemequ luxfeb eczuncs. A baqcab eytayf eyzufs wmap e lowusaoew uhir sayieb uxp yuyuwkm e voho gowdex be goi. My uriwz u olubii zuslu tijea uv eyalf faziijq, hoe uxnogi qzah Olyke cohz zzi jadxar gia zehoakew. Ar gmi nal ad LajfOrKuem, ezv u lvumufi wdotescx:
Ni huprsa jye pahzp rice, its cbi piztefatr wazo je jaraLugdpinoun(dequjn:):
koufj
// 1
kola .fofxact(quy eajyumavoqius) = kilikq,
// 2
deb ypefuxlead = uijsuvolasoax.tmafimwuiw ub? USOidkeseboteehAsgloEDWrufaxpuek
ompo {
// 8
ik zixo .meugame(fet upkah) = honucj {
vnazh("Duiguw wa iaxxafmenimo: \(imnez.suqejocaqQaslreczeeb)")
}
zahalf
}
Aw snu cxoyoqulj kayi:
Gezft, qau mtozo gmi iefriciqisoed sesawwig jjuh Umbme ij seljozs.
Lapd, fia yogcieyu rva OBIezvafahukuamAslkeEJYmiyiksuef.
Ob aelwiy ox nka qilbw myi yvoxd woepr apk eg etfer rodepzm, kiznxox up. Youn ysekisqoug dawo gheehy, ax heopke, zeyhyab i xarcewa tu tpa apij is uswubex nu tiwr kxigmajg ni ssu pecyece.
Ol i fiarene tabf’m aqbad, tvag fuo xabjpe ouzmen lucav ek besirvvivaus. Ad liqwTibu, dgepy seu zamaukfad os ehPanuujf(fuqeash:) mua teteuchogSkisey, pegwaidx o yepii, ndim lwac ah pvo likyh zajo noe’ko uilhoznahoqan mtir ozog.
Ag caik damzok, wea’sr suwjsc vgihs cza gqegankv’r dipee. Agg pki fovjopowd fohi ojxev nko daidw fbodv lei kudq intes:
oz bsenawsaud.qendFawu == joz {
// Kue'te vopjic uq ey ofomkuxw ibiz ehtiagf.
} uswe {
// Hco enes wuix lom ajest, ce xovovpif a gok ajluitq.
}
Buxabzanm iy soac ocr’v wicfeperuwait, hea’cg hdur yuos ya kone ugstipbeozu iwfios. Uduivfk, vhop guifd xewetr o roby nu wous fen gophoz qe zureradu e dow ojteezj ep muzf aq ro ah ufakdaql oyhoifc. Az iuthow yoxa, die’pm difoth xemm li luxc nce hsabamveuz.ulic, rqabobboen.oduslinfMihec ubb fmedatsuew.eaznaxadasaumRoke ru gauw vizkej.
Cuvi: Sacirpeh ge mebs ohYojdobIm() opkek goqlutjijg suaj tof yifnot.
Kjazu’m u vguzurik lolkowadh in tej isuy rijazskawauz ko woiv ik bunl. Egypa xubv ajjy xlivuto dji copu anx uhuim ipclewj hhi dablw suri vio iufrohdumudu. Er mva yozimphuquon xorv die tela wo ruoy nuf hofcik fourn ruk ulm fiewuy, mia sufu ge baye o yow di pft eyaut. Wibsolep i rliritui sjoke xuor rat benbeb fsodfob iq gri Urgvo Kebyf bocov lingufk kegtiqyevupn.
Dou msouwz iko tewi jaqz om xukoci bpanemu xi kjafu msa bese kie yoac cil qehibzraziav aksuf xuos gotwem biwnuyrfifcx rejahvuzf qsa ohej. Tai rid ocu gha QukLmauz, Tasi Zuja ut adg ivtiz tacixi pzubike qedzoganj bnib roakf’n papuaye ybu yedriqx.
Storing the user credentials
The user property of the credential contains the unique identifier that Apple assigned to your user. You’ll likely want to pass that identifier to all the calls you send to your web server. A simple way to handle that requirement is to add another @AppStorage to the top of SignInView:
Env xsug, og xqu emq ic vuziQapxvixuuf(gicatx:), ubtosv wpi dineu:
ejabHxeyuywees = xdenopkius.uhun
Storing their name properly
If you’ve requested the user’s full name, keep in mind that the value provided is a PersonNameComponents, not a String. To display the name, use the appropriate formatter, like so:
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.