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

如何获取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)
                        }
                    }
                }
            }
        
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值