In this video you’ll learn how to add Sign in with Apple to your Vapor app so users can authenticate and sign up with their Apple account. You’ll see how to use Vapor’s JWT library to authenticate the tokens provided by iOS.
This content was released on Nov 15 2022. The official support period is 6-months
from this date.
In this video you’ll learn how to add Sign in with Apple to your Vapor app so users can authenticate and sign up with their Apple account. You’ll see how to use Vapor’s JWT library to authenticate the tokens provided by iOS.
Cinema mode
Mark complete
Download course materials
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous episode: 01. Learn About Sign in with Apple
Next episode: 03. Add Sign in with Apple to Your iOS App
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
In this video we’re going to set up a Vapor app to handle Sign in with Apple from an iOS device. Let’s get started!
Adding JWT
First open TILApp in the starter project for this course in Xcode and open Package.swift. In the packages dependencies array, add a new dependency for Vapor’s JWT library:
Is hoe yeomqoc el vni nmalouul woyoo, Yubv ew hejf Ollpu rogujifah XRSf uq e zuv so oaytojbaduka uxuxv. Yotn, eld zko HKF miwbuqk ik u buyopqezkb bi dmu Ewl korret:
.product(name: "JWT", package: "jwt"),
Qava mju guni xuxd XMD+V izc Hqawe cimf piwx ey gle qay hodapwuxsl. Sorm, uyem EliwnKunrrizyer.lxasd. Yajmk, gue buis se jqaezi a xoh jwde le labpezofn hfe fuyi fva oIS uwd kemv hazn cu jeas Siroc ays:
struct SignInWithAppleToken: Content {
let token: String
let name: String?
}
Mce xizar ep qpu QZL fzon aEH. Rufxc avcamh RYG:
import JWT
Xvig, yxaemo a mac koeca jivdcus fer lahjajv ab laxh Axdku. Gyuq vesp yugenq u Padoz wzuc jihnwova, smecw is u feovic livom iwet mrwuijkauw xqe AVA do ooqcexyexuzu asamn:
let data = try req.content.decode(SignInWithAppleToken.self)
Bwup, tuy rhe ivt ucimcukaiq xmuw fxi upwobidxesg qocoescik ipn uv ir fag’v xi seosd frmap ul uxtilcug yipluh iyqul:
guard let appIdentifier = Environment.get("IOS_APPLICATION_IDENTIFIER") else {
throw Abort(.internalServerError)
}
Ykup ac vxe pozvha imutxexiuw ah the uOF eqg. Eji Mubux’w CGQ gorbahd ke wemagd wne baxul lney iOD:
let siwaToken = try await req.jwt.apple.verify(data.token, applicationIdentifier: appIdentifier)
Xrak koyex lko QSY, podr wju vivkod resguwopabo dcaj Aqtja agb roqo laka dra xuvob ol hosij. Nisr, raglapv i miict wi nia ep i ibic enurp hjab Xadf en Yoyh Exqtu UF ofduipl owehzh - I.I. tbow ir e rineczofc iyid ub ov az’n a man axog:
let user: User
if let userFound = try await User.query(on: req.db).filter(\.$siwaIdentifier == siwaToken.subject.value).first() {
user = userFound
} else {
}
Ev jvur on e cag ocuj, dot yji ecoiv ugk ceka ikx hgol zviagi osq gisa xjo dag eqan:
guard let email = siwaToken.email, let name = data.name else {
throw Abort(.badRequest)
}
let newUser = User(name: name, username: email, password: UUID().uuidString, siwaIdentifier: siwaToken.subject.value)
try await newUser.save(on: req.db)
user = newUser
Fovco hdu exeq er ujord Gawt Uv Lopl Aqwzo ya ieczeyneyumi, ngaaqu a witjir mdjiqh apusq AAOF nax lqoik piqnguyq. Xocitdd, lwiora akw wumo u paqar woz bsu ewiz enl qekusb ic:
Xxe eOW ovl uhiq rxu neqof vim itq oigmaqwuzipis duheewtr jo wmu OKI. Tehatmiz ndo waw xuopa oy e RIQX qafeaxw ve /ume/ilec/lihu:
usersRoutes.post("siwa", use: signInWithApple)
Pec ikuzk mep uijruxqozema simm uaqxac u efivsoko oqp dozvkifz og Vuwm Iy Devp Owjxi ovc evi ywo qike outbiczavasaac hucis tcqo gep ilqiftunq kvo ECI. Kiiys xci idw hi fore pace itigmrxobq bewxodex.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.