All Projects → tptpp → sign-in-with-apple

tptpp / sign-in-with-apple

Licence: MIT License
An example for sign-in-with-apple, golang-version.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to sign-in-with-apple

macos
macOS load bootup and optimization
Stars: ✭ 29 (+31.82%)
Mutual labels:  apple
Media
A beautiful and declarative cross-platform wrapper API for Apple's PhotoKit
Stars: ✭ 78 (+254.55%)
Mutual labels:  apple
Thoughtless
An iOS app that lets user quickly jot down thoughts with Markdown support
Stars: ✭ 24 (+9.09%)
Mutual labels:  apple
uvmac
µvMac - cleaned up fork of the Macintosh emulator Mini vMac
Stars: ✭ 28 (+27.27%)
Mutual labels:  apple
decimation.github.io
Cydia repo
Stars: ✭ 18 (-18.18%)
Mutual labels:  apple
homekit-qrcode
Generate a pairing HomeKit QR code label for your HomeKit accessory from the command line
Stars: ✭ 17 (-22.73%)
Mutual labels:  apple
reactnative-android-production
Step by step guid for compiling and installing React Native Android app [ bundled release version ] to your test device.
Stars: ✭ 51 (+131.82%)
Mutual labels:  sign
react-native-bounceable
Animate and bounce any component with RNBounceable for React Native
Stars: ✭ 26 (+18.18%)
Mutual labels:  apple
Sensors
A macOS application displaying the thermal, voltage and current sensor values.
Stars: ✭ 70 (+218.18%)
Mutual labels:  apple
Learning-Core-Audio-Swift-SampleCode
Swift sample code for the book, Learning Core Audio. The original sample code was written in C/Objective-C but I tried to make it in Swift version.
Stars: ✭ 114 (+418.18%)
Mutual labels:  apple
LAPSforMac
Local Administrator Password Solution for Mac
Stars: ✭ 29 (+31.82%)
Mutual labels:  apple
react-native-super-ellipse-mask
Apple flavored smooth corners for React Native
Stars: ✭ 55 (+150%)
Mutual labels:  apple
WacOS
A Linux distribution that mimics MacOS (modern and classic) iOS, and other Apple operating systems, but is open, customizable, and free to use on non-apple hardware.
Stars: ✭ 18 (-18.18%)
Mutual labels:  apple
reactjs-apple-musickit
Sample ReactJS Apple MusicKit Integration
Stars: ✭ 19 (-13.64%)
Mutual labels:  apple
Clean-macOS
💻 A simple script to setup a clean environment on macOS
Stars: ✭ 155 (+604.55%)
Mutual labels:  apple
ios code sign
iOS 签名简介
Stars: ✭ 23 (+4.55%)
Mutual labels:  apple
punic
Punic is a remote cache CLI built for Carthage and Apple .xcframework
Stars: ✭ 25 (+13.64%)
Mutual labels:  apple
health kit reporter
A Flutter wrapper for the HealthKitReporter library
Stars: ✭ 16 (-27.27%)
Mutual labels:  apple
sign-in-with-apple-js-node-example
Sign in with Apple using Apple JS and REST API
Stars: ✭ 48 (+118.18%)
Mutual labels:  apple
react-native-imaged-carousel-card
Fully customizable & Lovely Imaged Carousel Card for React Native
Stars: ✭ 70 (+218.18%)
Mutual labels:  apple

版权声明:本文为原创文章,未经允许不得转载。 https://blog.csdn.net/tptpppp/article/details/99288426

概述

本文是对AppleID登录接入的相关总结,希望对其他人能有帮助。

苹果在其WWDC19大会上提出了"Sign In with Apple"的概念,类似于微信一键登录,但也有些区别:

  • 微信存在一个UnionID、OpenID的概念,苹果只有一个AppleID;
  • 微信直接通过api就能拿到用户信息,而苹果拿到的是一个jwt,需要进行加解密。

相关参数

根据官方文档(链接见文末),AppleID登录遵循OAuth2.0协议,主要分为两步:1. 用户授权后获取code;2. 通过code换取token。以下流程在网页端和App端存在一定差异,主要是client_id和redirect_url不同,这里以网页端为例进行说明。

在发起流程前,你需要准备以下参数:

  • Team ID,10个字节的字符串,可以在苹果账户后台中看到,位于右上角

  • Key Id,10个字节的字符串,可以在苹果账户后台中看到

  • Client ID,这里要注意与code授权的平台保持一致。注意网页端与app端的差异,参见遇到的问题一

  • Private Key,一个.p8文件,只能从苹果官网下载一次

  • Redirect Url,code授权的回调url,app端可以不填

除Redirect Url外,其他几个参数主要用于生成client_secret。根据官方文档,client_secret是如下jwt采用ES256加密的结果:

{
    "alg": "ES256",                         // jwt加密算法,固定值
    "kid": "ABC123DEFG"                     // Key Id
}
{
    "iss": "DEF123GHIJ",                    // Team ID
    "iat": 1437179036,                      // jwt生成时间,精确到秒
    "exp": 1493298100,                      // jwt过期时间,unix时间戳,精确到秒
    "aud": "https://appleid.apple.com",     // 授权给此域名,固定值
    "sub": "com.mytest.app"                 // Client ID
}

golang实现

参见代码

遇到的问题

问题一 网页端/App端Client ID不同

  • 现象: {"error":"invalid_grant"}
  • 原因:client_id填写错误

网页端流程走通后,在调试App端的过程中,总是报错invalid_grant,后来发现是client_id填错了。网页授权登录填写的是Services Id,App端登录需要的是AppId,参见链接

参考

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].