<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Quang Đàm on Medium]]></title>
        <description><![CDATA[Stories by Quang Đàm on Medium]]></description>
        <link>https://medium.com/@damthieuquang?source=rss-64b901e0a952------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*VWIKCstkkQgbfdguZNi0UQ.jpeg</url>
            <title>Stories by Quang Đàm on Medium</title>
            <link>https://medium.com/@damthieuquang?source=rss-64b901e0a952------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 05:18:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@damthieuquang/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[iPhone của bạn đã bị nhiễm virus…: Cảnh giác với các thông báo giả mạo từ các trang web]]></title>
            <link>https://damthieuquang.medium.com/iphone-b%E1%BB%8B-virus-c%C3%A1ch-kh%E1%BA%AFc-ph%E1%BB%A5c-th%C3%B4ng-b%C3%A1o-l%E1%BB%ABa-%C4%91%E1%BA%A3o-221d5c8dd37c?source=rss-64b901e0a952------2</link>
            <guid isPermaLink="false">https://medium.com/p/221d5c8dd37c</guid>
            <dc:creator><![CDATA[Quang Đàm]]></dc:creator>
            <pubDate>Fri, 04 Jun 2021 03:25:34 GMT</pubDate>
            <atom:updated>2022-09-13T09:05:32.062Z</atom:updated>
            <content:encoded><![CDATA[<p>Bạn có bao giờ tự nhiên đang lướt web, xem phim hay đơn giản đang vọc iPhone mà tự nhiên thấy thông báo hết hồn: “điện thoại bạn bị nhiễm virus…”, “Dữ liệu của bạn đang gặp rủi ro!”.</p><p>Vừa rồi một chị bạn của mình cũng gặp trường hợp này và gọi hỏi mình cách khắc phục, mình cũng khá bất ngờ vì iPhone đó giờ có virus gì đâu mà có thông báo như vậy. Thế là mình đã kêu chị đó chia sẻ màn hình điện thoại (share screen) để có thể tìm nguyên nhân và khắc phục cho chị đó. Sau đây mình sẽ mô tả lại để bạn hoặc bất cứ ai đang bị và sẽ bị có thể khắc phục được vấn đề này.</p><h3>1. Để ý thông báo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*p0yNw53wRkwQ97T9jpCLzg@2x.jpeg" /><figcaption>Thông báo mà chúng ta hay bỏ qua</figcaption></figure><p>Nếu bạn để ý thì đây là thông báo sẽ thường xuyên nhảy ra bất thình lình khi bạn đang vào một số trang web truyện hoặc phim lậu nào đó. Thông thường người dùng sẽ không đọc bấm đại như một thói quen, và nếu bấm vào <strong>OK</strong> coi như bạn đã đồng ý cho “virus” hay “dữ liệu rủi ro” vào máy bạn rồi đó. Giải pháp lúc này là <strong>Cancel</strong> (<strong>Hủy</strong>) là xong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*PC-1PVD1jq2L2GHQTqLwnQ@2x.jpeg" /><figcaption>Thông báo các “sự kiện” đã được thêm vào lịch</figcaption></figure><h3>2. Khắc phục vấn đề</h3><p>Cơ bản vấn đề ở trên là khi bạn đồng ý thông báo trên thì có nghĩa bạn cho trang web đó thêm vào <strong>Calendar</strong> (<strong>Lịch</strong>) của iPhone danh sách các nhắc nhở các cuộc hẹn với nội dung được soạn sẵn như là “máy bị đã bị virus…” hay “dữ liệu bạn đang gặp rủi ro”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*8gqioxSoGt6LQzb2LJbhsQ.gif" /><figcaption>Calendar (lịch) của bạn sẽ như thế này</figcaption></figure><p>Để khắc phục bạn sẽ thao tác như sau:</p><p>Tiếng Anh: Settings → Calendar → Accounts</p><p>Tiếng Việt: Cài đặt → Lịch → Tài khoản</p><p>Bạn quan sát xem có <strong>Account</strong> (<strong>tài khoản</strong>) như trên không, nếu xác định đúng là nó thì xóa nó đi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*xrA3AXhYVWheG336lcxClg.gif" /><figcaption>Xóa Account (tài khoản) không mong muốn</figcaption></figure><p>Sau khi thực hiện xong thao tác này, bạn quay lại danh sách <strong>Calendar</strong> (<strong>lịch</strong>) khi nãy sẻ không thấy các thông báo đó nữa.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*KPwpgpXqqw_C0iXrmD_L8g.gif" /><figcaption>Kết quả</figcaption></figure><p>Qua bài viết này mình hy vọng nó sẽ giúp được những bạn nào không rành về công nghệ mà lại gặp các thông báo thế này không bị hoang mang mà có cách khắc phục và hiểu được nguyên nhân gốc rễ để xử lý.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=221d5c8dd37c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sign In With Apple: What is it and how it works]]></title>
            <link>https://damthieuquang.medium.com/sign-in-with-apple-what-is-it-and-how-it-works-119bffa0ba64?source=rss-64b901e0a952------2</link>
            <guid isPermaLink="false">https://medium.com/p/119bffa0ba64</guid>
            <dc:creator><![CDATA[Quang Đàm]]></dc:creator>
            <pubDate>Sat, 11 Apr 2020 09:52:15 GMT</pubDate>
            <atom:updated>2020-04-11T12:17:18.347Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sign In With Apple: What is it and how to implement it</h3><p>Sign in With Apple is a new feature on iOS 13, which is designed to let the user create accounts for apps and websites using your Apple ID, so the end-user doesn’t have to give away their personal information.</p><h3>How Apple Sign-In works</h3><p>It looks like Facebook and Google, Sign in With Apple allows users to register/login to an application without giving their email or password manually. Developers like us won’t know the user ‌Apple ID‌ and are only provided with their name and email address, though there is also an option to hide your email address if desired.</p><blockquote>Apple is requiring all apps that offer sign in with Google, Facebook, or Twitter options to also offer Sign in with Apple,<a href="https://developer.apple.com/news/?id=03262020b"> but there is an June 2020 deadline</a>, so the feature may not be available in apps right away. Eventually, all apps that allow you to sign in with other accounts from Google, Twitter, and Facebook will also be required to offer Sign in with Apple.</blockquote><h3>Where it works</h3><p>Sign in with Apple works on the web and iOS. So if you have a login for an app that also has a website, you can use Sign in with Apple as a login option in both places.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hWxa0vUUHqN-LAKI" /><figcaption><em>Sign In on the web</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VICElMkjOAH9EYAg" /><figcaption><em>Sign in on the app</em></figcaption></figure><h3>Implement on the mobile side</h3><p>Open the XCode interface to select the target you are adding Sign In Apple (SIA) to and select Signing &amp; Capabilities → Capabilities → Sign In Apple</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E5djtqCX8Lb04zME" /><figcaption>Register SIA on XCode</figcaption></figure><p>Then navigate to the controller that you want to install this feature and import the <em>AuthenticationServices</em> class.</p><p>Because the sign-in button doesn’t have an IBOutlet to drag and drop into the graphical interface, we have to declare it as a regular UIButton and set its size on the screen.</p><p>For this example, I wrote in Objective C:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_4zAj8CNg9jfZ3B5P9w3nw.png" /><figcaption>Initialize login button with Apple</figcaption></figure><p>Then proceed to the layout of this button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XlRRhGr5ULR5P2xT965DdQ.png" /><figcaption>Layout interface for the login button</figcaption></figure><p>If you are not familiar with this way and still want to use XIB or storyboard to design the interface faster, you can use UIStackView in this case.</p><pre>@IBOutlet weak var loginProviderStackView: UIStackView!</pre><p>Drag the IBOutlet of UIStackView into the desired controller. Then install the Sign In Apple button as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DT5nvrnoY3gAX8NeERqkKQ.png" /><figcaption>Install login button using via UIStackView</figcaption></figure><p>The result after performing either of the two steps above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*lq1REZdlXZxmP1fScW6Nmg.png" /><figcaption>Result after layout</figcaption></figure><p>Now it is time to complete the event handling for the user logged in through this button. When the user clicks this button, we make a request to Apple with the email permission and the user’s full name.</p><blockquote>Note: you need to read more about <a href="https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2">OAuth</a> to know how to log in to this type of Apple, this is a common standard that Facebook and Google are also using.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ekSHArcCf7rFcOC-6zY6ig.png" /><figcaption>Handle event when user touch on the button</figcaption></figure><p>Oh, there’s a delegate, so let’s implement these delegates. <em>ASAuthorizationControllerDelegate</em>, there are only two delegates</p><pre>optional func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization)</pre><pre>optional func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error)</pre><p>Although two delegates are optional, you have to apply it.</p><p>For delegate didCompleteWithAuthorization, we will implement the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQXjSrECrfFMhQbHjNirWg.png" /><figcaption>Handle for the case AppleIDCredentail</figcaption></figure><p>Please pay attention to the authorization code because this is what we send to the backend (BE) for them to use and verify with Apple’s server to get other information about the user. Besides, data such as full name and email will be provided the first time when the user uses this function, the next time there will be only userID information, so you should save this information (if you need)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i9-IeRFLE5XG7qOMq6WiaA.png" /><figcaption>The user’s information in the first time login</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*paLgm0Jp8wzr3iZXp8h0Fg.png" /><figcaption>and the second time</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wq9YkaBYYRmSCMDeNxb-Sg.png" /><figcaption>Handle for the case username and password be stored in iCloud Keychain.</figcaption></figure><p>If the credential is a password type, a popup will appear, allowing the user to authenticate with an existing account.</p><p>Yeah, we have implemented on the mobile side. A part of my tutorial prefers from the example of <a href="https://developer.apple.com/documentation/authenticationservices/implementing_user_authentication_with_sign_in_with_apple">Apple</a>.</p><h3>Implementation on the server-side</h3><p>If you have read up to this section and lazy to read the link about the OAuth above I mentioned, there is a picture summarizing the operation of the Sign In Apple:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y_iEAGsyjDwknAGG.png" /><figcaption>How Authentication works (illustration is from Auth0 service)</figcaption></figure><p>The above steps are not difficult to understand; Auth0 acts as your server are responsible for receiving authorization code from mobile and verifying with apple server to get relevant information.</p><p>Installation on the server, you can have two ways to perform it, use the service of <a href="https://auth0.com/"><strong>Auth0</strong></a><strong>,</strong> or set yourself on your server.</p><h4>Auth0</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*TMXYOmzxJONbOJeRBA38Gg.png" /><figcaption>Go to the social section to use the Sign In Apple service on Auth0</figcaption></figure><p>Turn on the Apple service on the right and configure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHO27uEmPUzGT0UQoPR69g.png" /><figcaption>Configure parameters for the app</figcaption></figure><h4>Client ID</h4><p>The Client ID here is the service ID created by the portal.</p><h4>Client Secret Signing Key</h4><p>It is the private key you got it in the process of creating your service ID, and related information will be available, this key is in the <strong>* .p8</strong> file, note that this file can only be downloaded once only, so be careful.</p><h4>Apple Team ID</h4><p>It is the team ID in the membership details section.</p><h4>Key ID</h4><p>It is the ID during the service ID creation process.</p><p>After the configuration is complete, go back to the dashboard → application and create the app, select the SDK Sign In With Apple, and then follow the instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HMaU_4tbLkUZLCgMVoMO7Q.png" /><figcaption>Results after creating the app</figcaption></figure><p>Opening the settings section, and select Application Tokens → show advanced settings and configure this more</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lH2T0HkBttCPSB0Z6RVkKQ.png" /><figcaption>Further configuration in the advanced setting</figcaption></figure><h3>Custom Server</h3><p>Because I have not much experience in the backend, so I cannot guide how to configure on the server in detail, but I will simulate steps to do and emulate through Postman.</p><p>In the Authentication operation model of the image above, the step to get authorization code in mobile is step 2, and now we will continue to step 3, send that code to our server (Postman) and get back information from apple (4,5,6)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8aec88SXxR5W_-GpDkWWyg.png" /><figcaption>Data prepared for the Postman</figcaption></figure><h4>Client ID</h4><p>It is the App ID (bundle ID) of the app.</p><blockquote>You should be aware that this Client ID will be different if the authorization code is generated from the web; this time, the Service ID will be made from the portal.</blockquote><h4>Client Secret</h4><p>Generated from information such as Team ID, Key ID … to create. You can watch this <a href="https://github.com/GeneaLabs/laravel-sign-in-with-apple">link</a>. Just pay attention to the 4th step, how to help us create the client secret.</p><h4>Code</h4><p>Authorization code from mobile or web.</p><p>Details in <a href="https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens">here</a>.</p><p>The postman result returns the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5huNwwUL-XyOl8i7NmLQw.png" /><figcaption>The following results are validated with Apple</figcaption></figure><p>Getting this result means that your authorization code is created correctly and that Authentication with apple will succeed. The remaining is to assemble the code with the backend again.</p><p>Except for the steps above, you need to create a service ID for Sign In With Apple, you should find it in other sites, so I will not include it in an article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=119bffa0ba64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sign In With Apple: Cách thức hoạt động và cài đặt.]]></title>
            <link>https://damthieuquang.medium.com/sign-in-with-apple-c%C3%A1ch-th%E1%BB%A9c-ho%E1%BA%A1t-%C4%91%E1%BB%99ng-v%C3%A0-c%C3%A0i-%C4%91%E1%BA%B7t-e33e43b19818?source=rss-64b901e0a952------2</link>
            <guid isPermaLink="false">https://medium.com/p/e33e43b19818</guid>
            <category><![CDATA[in]]></category>
            <category><![CDATA[signs]]></category>
            <category><![CDATA[sign-in-with-apple]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[Quang Đàm]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 07:28:36 GMT</pubDate>
            <atom:updated>2022-09-13T09:01:32.687Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sign In With Apple là gì? Cách thức hoạt động và cài đặt.</h3><p><a href="https://medium.com/@damthieuquang/sign-in-with-apple-what-is-it-and-how-it-works-119bffa0ba64">English version</a></p><p>Sign in Apple là chức năng được giới thiệu trên iOS 13. Tính năng này được thiết kế để giúp người dùng có thể tạo tài khoản và đăng nhập vào ứng dụng một cách dễ dàng mà không phải cung cấp thông tin cá nhân của mình cho nhà phát triển ứng dụng hoặc website.</p><h3>Cách thức hoạt động</h3><p>Sign in Apple là tính năng không khác mấy nếu so sánh nó với Google hoặc Facebook, cho phép người dùng tạo hoặc đăng nhập vào ứng dụng hoặc website một cách dễ dàng mà không cần phải cung cấp thông tin một cách thủ công. Anh em Developer như chúng ta sẽ không thể biết được thông tin Apple ID, mà chỉ biết được tên của người dùng và email, nhưng nếu họ không cho phép biết email thì chúng ta cũng chỉ nhận được email giả thôi.</p><blockquote>Theo thông tin từ Apple, <a href="https://developer.apple.com/news/?id=03262020b">kể từ tháng 6 năm 2020</a>, tất cả các ứng dụng nếu sử dụng đăng nhập bằng Facebook, Google hoặc Twitter thì phải có cả chức năng Sign in Apple. Ngoại lệ một số ứng dụng liên quan đến giáo dục và một số ứng dụng khác thì có thể không cần phải áp dụng quy định này, xem thêm ở <a href="https://developer.apple.com/sign-in-with-apple/get-started/">link</a> này nhé.</blockquote><h3>Tính năng này hoạt động ở đâu?</h3><p>Sign in Apple sẽ hoạt động trên nền tảng website và iOS. Do đó chúng ta có thể đăng nhập trên website hoặc trên ứng dụng hoặc cả 2 nền tảng đó cùng lúc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0eVYpr-FNNQQZPhj" /><figcaption>Giao diện hiển thị trên website</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3gC3wd_7vI_75ogT" /><figcaption>Giao diện hiển thị trên ứng dụng</figcaption></figure><h3>Cài đặt trên Mobile</h3><p>Mở giao diện XCode chọn target mà bạn đang mà muốn thêm Sign In Apple (SIA) và chọn Signing &amp; Capabilities → Capabilities → Sign In Apple</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bdmHpzy-vdVo2myo" /><figcaption>Đăng kí SIA trên XCode</figcaption></figure><p>Sau đó tìm đến controller nào mà bạn muốn cài đặt tính năng này và import thêm class AuthenticationServices.</p><p>Bởi vì nút sign in không có IBOutlet để kéo thả vào giao diện đồ hoạ nên chúng ta phải tự khai báo nó như một UIButton thông thường và set kích thước cho nó trên màn hình.</p><p>Ví dụ này mình viết bằng Objective C:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_4zAj8CNg9jfZ3B5P9w3nw.png" /><figcaption>Khởi tạo nút đăng nhập bằng Apple</figcaption></figure><p>Sau đó tiến hành layout giao diện của nút này:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XlRRhGr5ULR5P2xT965DdQ.png" /><figcaption>Layout giao diện cho nút đăng nhập</figcaption></figure><p>Nếu như bạn không quen với cách thức này mà vẫn muốn dùng xib hay storyboard để layout giao diện nhanh hơn thì có thể dùng UIStackView trong trường hợp này.</p><pre>@IBOutlet weak var loginProviderStackView: UIStackView!</pre><p>Kéo IBOutlet của UIStackView vào controller mong muốn. Sau đó cài đặt nút Sign In Apple như sau:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DT5nvrnoY3gAX8NeERqkKQ.png" /><figcaption>Cài đặt nút đăng nhập bằng thông qua UIStackView</figcaption></figure><p>Thành quả sau khi thực hiện một trong hai bước trên:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*lq1REZdlXZxmP1fScW6Nmg.png" /><figcaption>Giao diện sau khi đã layout</figcaption></figure><p>Bây giờ là đến bước thực hiện việc xử lý sự kiện người dùng đăng nhập thông qua nút này. Khi người dùng bấm vào nút này, chúng ta sẽ thực hiện gửi yêu cầu đến Apple với quyền email và full name của người dùng.</p><blockquote>Lưu ý: cần đọc thêm <a href="https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2">OAuth</a> để biết cách thức đăng nhập kiểu này của Apple, đây là một chuẩn chung mà Facebook và Google cũng đang sử dụng.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ekSHArcCf7rFcOC-6zY6ig.png" /><figcaption>Xử lý sự kiện người dùng bấm vào nút đăng nhập.</figcaption></figure><p>Ồ, có delegate kìa, vậy là phải đi implement delegate này nhé. ASAuthorizationControllerDelegate thì chỉ có 2 delegates là:</p><pre>optional func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization)</pre><pre>optional func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error)</pre><p>Tuy để là optional nhưng phải implement hết nhé.</p><p>Đối với delegate <em>didCompleteWithAuthorization, </em>chúng ta sẽ implement như sau:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQXjSrECrfFMhQbHjNirWg.png" /><figcaption>Xử lý cho trường hợp kết quả là AppleIDCredentail</figcaption></figure><p>Các bạn hãy chú ý đến authCode vì đây chính là cái chúng ta gửi đến backend(BE) để họ dùng và xác minh với server của Apple lấy thêm thông tin khác của người dùng. Ngoài ra, các thông tin như full name và email sẽ được cung cấp đúng lần đầu tiên khi người dùng sử dụng chức năng này, các lần sau sẽ chỉ còn thông tin userID, do đó các bạn nên lưu thông tin này lại(nếu cần)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i9-IeRFLE5XG7qOMq6WiaA.png" /><figcaption>Thông tin lần đầu tiên người dùng đăng nhập bằng Sign In Apple</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*paLgm0Jp8wzr3iZXp8h0Fg.png" /><figcaption>Chỉ còn userID kể từ lần đăng nhập thứ 2 trở đi</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wq9YkaBYYRmSCMDeNxb-Sg.png" /><figcaption>Xử lý cho trường hợp kết quả là Password được lưu ở iCloud</figcaption></figure><p>Vậy đoạn này dùng để làm gì? Nếu credential là kiểu password thì sẽ hiện thông báo cho phép người dùng xác thực với tài khoản đã tồn tại.</p><p>Phù, thế là xong phần cài đặt cho phía mobile. Hướng dẫn của mình trích một phần từ ví dụ của Apple thông qua <a href="https://developer.apple.com/documentation/authenticationservices/implementing_user_authentication_with_sign_in_with_apple">link</a> này nhé.</p><h3>Cài đặt trên Server</h3><p>Nếu bạn đã đọc tới phần này và lười đọc link về cái OAuth phía trên mình đề cập thì có một cái hình tóm tắt quá trình hoạt động của cái Sign In Apple như sau:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y_iEAGsyjDwknAGG.png" /><figcaption>Cách thức hoạt động Authentication của Sign In Apple (hình minh hoạ lấy từ dịch vụ Auth0)</figcaption></figure><p>Các bước trên cũng không khó hiểu mấy, ở đây Auth0 đóng vai trò là server của các bạn, chịu trách nhiệm chính nhận authorization code từ mobile và xác minh lại với server của apple để lấy các thông tin liên quan.</p><p>Cài đặt ở server các bạn có thể có hai cách để thực hiện, nếu muốn cấu hình nhanh gọn thì dùng dịch vụ của <a href="https://auth0.com/"><strong>Auth0</strong></a> hoặc là tự cấu hình trên server của mình.</p><h4>Auth0</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*TMXYOmzxJONbOJeRBA38Gg.png" /><figcaption>Vào mục social để dùng dịch vụ Sign In Apple trên Auth0</figcaption></figure><p>Bật dịch vụ Apple ở bên phải lên và cấu hình như sau:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHO27uEmPUzGT0UQoPR69g.png" /><figcaption>Cấu hình các thông số cho app</figcaption></figure><h4>Client ID</h4><p>Client ID ở đây chính là service ID được tạo bằng portal.</p><h4>Client Secret Signing Key</h4><p>Đây chính là private key mà trong quá trình bạn tạo service ID và các thông tin liên quan sẽ có, key này nằm trong file <strong>*.p8</strong>, lưu ý là file này chỉ down được 1 lần duy nhất nên phải giữ kĩ nhé.</p><h4>Apple Team ID</h4><p>Đây chính là team ID trong mục membership details đấy nhé.</p><h4>Key ID</h4><p>Đây chính là ID trong quá trình tạo service ID.</p><p>Sau khi cấu hình xong thì ta quay lại dashboard → application và tạo ứng dụng, chọn SDK là Sign In With Apple rồi làm theo hướng dẫn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HMaU_4tbLkUZLCgMVoMO7Q.png" /><figcaption>Kết quả sau khi tạo app</figcaption></figure><p>Nhưng như thế chưa xong đâu, mở mục setting nên chọn Application Tokens → show advanced setting rồi cấu hình thêm cái này</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lH2T0HkBttCPSB0Z6RVkKQ.png" /><figcaption>Cấu hình thêm trong advanced setting</figcaption></figure><p>Thế là xong, chỉ cần làm theo hướng dẫn còn lại của Auth0 thì việc cấu hình Sign In With Apple xem như đã xong.</p><h3>Custom Server</h3><p>Do không chuyên lắm về backend nên mình không thể hướng dẫn chi tiết cách cấu hình trên server, tuy nhiên mình sẽ mô phỏng lại các bước cần làm và giả lập thông qua Postman, một cách để dev mobile chúng ta độc lập test không phụ thuộc vào server nếu họ cấu hình chưa xong.</p><p>Trong mô hình hoạt động của Authentication của hình trên, bước lấy được authorization code ở mobile đã là bước 2, nay ta sẽ thực hiện tiếp bước 3, gửi code đó lên server của chúng ta (postman) và nhận lại thông tin từ apple (4,5,6)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8aec88SXxR5W_-GpDkWWyg.png" /><figcaption>Thông tin chuẩn bị cho postman</figcaption></figure><h4>Client ID</h4><p>Đây chính là App ID (bundle ID) của app</p><blockquote>Nên lưu ý rằng Client ID này sẽ khác nếu authorization code được tạo ra từ web, lúc đó đây sẽ Service ID được tạo từ portal.</blockquote><h4>Client Secret</h4><p>Được tạo ra từ các thông tin như Team ID, Key ID… để tạo ra. Bạn có thể xem theo <a href="https://github.com/GeneaLabs/laravel-sign-in-with-apple">link</a> này. Chỉ cần chú ý tới bước thứ 4 thôi, cách giúp chúng ta tạo ra client secret.</p><h4>Code</h4><p>Authorization code từ mobile hoặc web.</p><p>Chi tiết của các thông tin này ở <a href="https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens">đây</a> nhé.</p><p>Kết quả của postman trả về như sau:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5huNwwUL-XyOl8i7NmLQw.png" /><figcaption>Kết quả sau xác thực với Apple</figcaption></figure><p>Nhận được kết quả này có nghĩa là authorization code của bạn tạo ra chính xác và việc xác thực với apple sẽ thành công. Việc còn lại là ráp code với backend nữa là xong nhé.</p><p>Ngoài các bước trên thì vẫn còn bước tạo service ID cho Sign In With Apple, do đã có rất nhiều bài viết về cách tạo nên mình không đưa vào bài viết này.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e33e43b19818" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>