-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/U-is-Ni-in-Korea/Server-…
…United into develop
- Loading branch information
Showing
10 changed files
with
112 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.universe.uni.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record ApplePayload( | ||
@JsonProperty("aud") | ||
String aud, | ||
@JsonProperty("auth_time") | ||
Long authTime, | ||
@JsonProperty("c_hash") | ||
String cHash, | ||
@JsonProperty("email") | ||
String email, | ||
@JsonProperty("email_verified") | ||
String emailVerified, | ||
@JsonProperty("exp") | ||
Long exp, | ||
@JsonProperty("iat") | ||
Long iat, | ||
@JsonProperty("is_private_email") | ||
String isPrivateEmail, | ||
@JsonProperty("iss") | ||
String iss, | ||
@JsonProperty("nonce_supported") | ||
Boolean nonceSupported, | ||
@JsonProperty("sub") | ||
String sub | ||
) { | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/universe/uni/domain/AppleTokenDecodeManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.universe.uni.domain; | ||
|
||
import java.util.Base64; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.universe.uni.exception.UnauthorizedException; | ||
import com.universe.uni.exception.dto.ErrorType; | ||
|
||
@Component | ||
public class AppleTokenDecodeManager implements AppleTokenManager { | ||
|
||
@Override | ||
public String decodeEmail(String token) { | ||
String[] encodedToken = token.split("\\."); | ||
String encodedPayload = encodedToken[1]; | ||
Base64.Decoder decoder = Base64.getDecoder(); | ||
String payLoad = new String(decoder.decode(encodedPayload)); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
ApplePayload applePayload = null; | ||
try { | ||
applePayload = mapper.readValue(payLoad, ApplePayload.class); | ||
} catch (JsonProcessingException e) { | ||
throw new UnauthorizedException(ErrorType.UNSUPPORTED_TOKEN); | ||
} | ||
return applePayload.email(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.universe.uni.domain; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
||
public interface AppleTokenManager { | ||
|
||
String decodeEmail(String token); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters