• Apple 注销账户 Revoke Token


    首先查看官方文档:Revoke tokens
    在这里插入图片描述

    @param client_id:App的bundleid
    @param client_secret:这个需要通过p8文件计算得到,稍后讲解
    @param token:配合参数token_type_hint,根据参数类型决定toke类型:refresh_token或access_token,需要使用https://appleid.apple.com/auth/token获取
    @token_type_hind:指定参数token的数据类型refresh_token或access_token

    如何获取p8文件?
    登录苹果开发平台,选择Certificates, Identifiers & Profiles,选择keys
    在这里插入图片描述
    在这里插入图片描述

    如何计算client_secret?
    使用ruby脚本,代码内容如下

    require "jwt"
    key_file = "./xxxx.p8"
    team_id = "xxx"
    client_id = "xxxx"
    key_id = "xxxx"
    validity_period = 180 # In days. Max 180 (6 months) according to Apple docs.
    
    private_key = OpenSSL::PKey::EC.new IO.read key_file
    
    token = JWT.encode(
       {
          iss: team_id,
          iat: Time.now.to_i,
          exp: Time.now.to_i + 86400 * validity_period,
          aud: "https://appleid.apple.com",
          sub: client_id
       },
       private_key,
       "ES256",
       header_fields=
       {
          kid: key_id 
       }
    )
    puts token
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    如何获取refresh_token or access_token?
    在这里插入图片描述
    下面只讲解三个参数,其他参数同上

    @param grant_type:如果grant_type=“authorization_code"则使用参数code的值,如果grant_type=” refresh_token"则使用参数 refresh_token的值。
    @param code:配合参数grant_type使用
    @param refresh_token:配合参数grant_type使用

    下面是基于swiftyHttp实现的Post接口:

    func doPost(url:String,params:[String:Any],headers:[String:String],completion:@escaping (_:Bool,_:String?,_:[String:Any]?)->Void,userParam:[String:Any]?){
            
            print("doPost:\(url):\(params)")
            HTTP.POST(url,parameters: params,headers: headers){ response in
                    if let err = response.error{
                        print("error:\(err.localizedDescription)--\(String(describing: response.text))")
                        if Thread.isMainThread{
                            if response.text != nil{
                                completion(false,String(describing: response.text!),userParam)
                            }
                            else{
                                completion(false,err.localizedDescription,userParam)
                            }
                        }else{
                            DispatchQueue.main.async {
                                if response.text != nil{
                                    completion(false,String(describing: response.text!),userParam)
                                }
                                else{
                                    completion(false,err.localizedDescription,userParam)
                                }
                            }
                        }
                    }else{
                        print("data:\(String(describing: response.text))")
                        if Thread.isMainThread{
                            completion(true,response.text,userParam)
                        }else{
                            DispatchQueue.main.async {
                                completion(true,response.text,userParam)
                            }
                        }
                    }
                }
            
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
  • 相关阅读:
    1.10.C++项目:仿muduo库实现并发服务器之Acceptor模块的设计
    Spark-core面试知识点
    华为FPGA工程师面试题
    【附源码】Python计算机毕业设计汽车租赁系统
    vue3 Composition 组合式API+TypeScript基本使用
    3.css的各种选择器
    洲际酒店及度假村焕新开拓,缔造难以忘怀的非凡时刻
    robots.txt漏洞
    Delta Lake 是什么?
    数据库 与 数据仓库
  • 原文地址:https://blog.csdn.net/CAir2/article/details/125515570