首先查看官方文档: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)
}
}
}
}
}