반응형
최근 애플 앱 심사 거절 이유로 회원탈퇴를 하는 경우 revoke token 처리를 해야한다고 한다.
클라단에서 처리를 못하기에 서버단에서 처리하기로 결정하고 서버에서 처리한다.
https://developer.apple.com/documentation/sign_in_with_apple/revoke_tokens
//client_secret 생성
public static string GenerateAppStoreJwtToken(string teamId, string keyId, string clientId, string p8key)
{
var aud = "https://appleid.apple.com";
string iss = teamId;
string sub = clientId;
string kid = keyId;
IList<Claim> claims = new List<Claim> {
new Claim ("sub", sub)
};
try
{
var cngKey = CngKey.Import(Convert.FromBase64String(p8key), CngKeyBlobFormat.Pkcs8PrivateBlob);
var signingCred = new SigningCredentials(new ECDsaSecurityKey(new ECDsaCng(cngKey)),
SecurityAlgorithms.EcdsaSha256);
var token = new JwtSecurityToken(iss,
aud,
claims,
DateTime.Now,
DateTime.Now.AddDays(180),
signingCred);
token.Header.Add("kid", kid);
token.Header.Remove("typ");
JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();
return tokenHandler.WriteToken(token);
}
catch(Exception ex)
{
//로그 출력
return null;
}
}
private async Task<bool> SendAppleRevokeToken(string token)
{
var clientSecret = GenerateAppStoreJwtToken(AppleTeamId,
AppleTeamId,
AppleClientId,
ApplePrivateKey);
if(string.IsNullOrEmpty(clientSecret) == true)
{
Log.Error($"failed to generate token!");
return false;
}
var parameters = new Dictionary<string, string>
{
{ "client_id", AppleClientId },
{ "client_secret", clientSecret },
{ "token", token },
{ "token_type_hint", "access_token" }
};
//post send
var response = await HttpRequester.Get(@"https://appleid.apple.com/auth/revoke", parameters);
return string.IsNullOrEmpty(response) == false;
}
반응형
'개발관련 > ETC..' 카테고리의 다른 글
aws ec2 프리티어 메모리 부족 (0) | 2023.09.22 |
---|---|
Linux에 서비스 등록 (0) | 2023.01.10 |
AWS CodeBuild, CodeDeploy (0) | 2019.07.25 |
객체 지향 설계의 원칙>SOLID (0) | 2019.05.08 |
javascript> Drag & Drop 파일 읽기 (0) | 2018.12.05 |