Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions DevLog/Infra/Service/SocialLogin/AppleAuthenticationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,31 @@ final class AppleAuthenticationService: AuthenticationService {
}

func unlink(_ uid: String) async throws {
let accessToken = try await refreshAppleAccessToken()
do {
logger.info("Starting Apple access token refresh for unlink. uid: \(uid)")
let accessToken = try await refreshAppleAccessToken()

try await revokeAppleAccessToken(token: accessToken)
logger.info("Starting Apple access token revocation for unlink. uid: \(uid)")
try await revokeAppleAccessToken(token: accessToken)

let tokensRef = store.document("users/\(uid)/userData/tokens")
let tokensRef = store.document("users/\(uid)/userData/tokens")

let doc = try await tokensRef.getDocument()
logger.info("Starting Apple token document fetch for unlink. uid: \(uid)")
let doc = try await tokensRef.getDocument()

if doc.exists {
try await tokensRef.updateData([
"appleRefreshToken": FieldValue.delete()
])
}
if doc.exists {
logger.info("Starting Apple refresh token deletion from Firestore for unlink. uid: \(uid)")
try await tokensRef.updateData([
"appleRefreshToken": FieldValue.delete()
])
}

_ = try await user?.unlink(fromProvider: providerID.rawValue)
logger.info("Starting Firebase Apple provider unlink. uid: \(uid)")
_ = try await user?.unlink(fromProvider: providerID.rawValue)
} catch {
logger.error("Failed to unlink Apple account", error: error)
throw error
}
}

// Apple 인증 메서드
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,17 @@ final class GithubAuthenticationService: NSObject, AuthenticationService {
}

func unlink(_ uid: String) async throws {
logger.info("Unlinking GitHub account for user: \(uid)")

do {
logger.info("Starting GitHub access token revocation for unlink. uid: \(uid)")
try await revokeAccessToken()

let tokensRef = store.document("users/\(uid)/userData/tokens")

logger.info("Starting GitHub access token deletion from Firestore for unlink. uid: \(uid)")
try await tokensRef.updateData(["githubAccessToken": FieldValue.delete()])

logger.info("Starting Firebase GitHub provider unlink. uid: \(uid)")
_ = try await user?.unlink(fromProvider: providerID.rawValue)

logger.info("Successfully unlinked GitHub account")
} catch {
logger.error("Failed to unlink GitHub account", error: error)
throw error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ final class GoogleAuthenticationService: AuthenticationService {
}

func unlink(_ uid: String) async throws {
logger.info("Starting Google disconnect for unlink. uid: \(uid)")
GIDSignIn.sharedInstance.signOut()
try await GIDSignIn.sharedInstance.disconnect()

logger.info("Starting Firebase Google provider unlink. uid: \(uid)")
_ = try await user?.unlink(fromProvider: AuthProviderID.google.rawValue)
}
Comment on lines 121 to 128
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

다른 인증 서비스(AppleAuthenticationService, GithubAuthenticationService)의 unlink 함수와 일관성을 유지하기 위해 do-catch 블록을 추가하는 것을 제안합니다. 이렇게 하면 오류 발생 시 로깅을 통해 문제를 더 쉽게 추적하고 디버깅할 수 있습니다.

    func unlink(_ uid: String) async throws {
        do {
            logger.info("Starting Google disconnect for unlink. uid: \(uid)")
            GIDSignIn.sharedInstance.signOut()
            try await GIDSignIn.sharedInstance.disconnect()

            logger.info("Starting Firebase Google provider unlink. uid: \(uid)")
            _ = try await user?.unlink(fromProvider: AuthProviderID.google.rawValue)
        } catch {
            logger.error("Failed to unlink Google account", error: error)
            throw error
        }
    }


Expand Down
27 changes: 17 additions & 10 deletions Firebase/functions/src/auth/apple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,19 @@ export const revokeAppleAccessToken = onCall({

try {
const { token } = request.data;
const { teamId, clientId, keyId, privateKey } = getAppleConfiguration();

if (!token) {
throw new HttpsError("invalid-argument", "Token is required");
}

// JWT 생성
console.log("Starting Apple token revocation", {
uid: request.auth.uid
});

console.log("Starting Apple configuration load for token revocation");
const { teamId, clientId, keyId, privateKey } = getAppleConfiguration();

console.log("Starting Apple client secret creation for token revocation");
const clientSecret = jwt.sign({}, privateKey, {
algorithm: "ES256",
expiresIn: "5m",
Expand All @@ -293,14 +299,15 @@ export const revokeAppleAccessToken = onCall({
keyid: keyId,
});

// Apple 서버에 토큰 취소 요청
await axios.post("https://appleid.apple.com/auth/revoke",
new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
token: token,
token_type_hint: "access_token" // access_token 또는 refresh_token 지정 가능
}).toString(), {
console.log("Starting Apple revoke API request");
await axios.post(
"https://appleid.apple.com/auth/revoke",
new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
token: token,
token_type_hint: "access_token" // access_token 또는 refresh_token 지정 가능
}).toString(), {
headers: {"Content-Type": "application/x-www-form-urlencoded"},
});

Expand Down