-
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.
Browse files
Browse the repository at this point in the history
[FIX] 애플 소셜 로그인 방식 수정
- Loading branch information
Showing
13 changed files
with
397 additions
and
21 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
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 |
---|---|---|
|
@@ -41,3 +41,6 @@ out/ | |
|
||
## QClass ## | ||
src/main/generated/ | ||
|
||
## Apple Login Key File ## | ||
*.p8 |
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
41 changes: 41 additions & 0 deletions
41
src/main/java/org/websoso/WSSServer/domain/UserAppleToken.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,41 @@ | ||
package org.websoso.WSSServer.domain; | ||
|
||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.OneToOne; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class UserAppleToken { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
@Column(nullable = false) | ||
private Long userAppleTokenId; | ||
|
||
@Column(nullable = false) | ||
private String appleRefreshToken; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
private UserAppleToken(User user, String appleRefreshToken) { | ||
this.user = user; | ||
this.appleRefreshToken = appleRefreshToken; | ||
} | ||
|
||
public static UserAppleToken create(User user, String appleRefreshToken) { | ||
return new UserAppleToken(user, appleRefreshToken); | ||
} | ||
} |
11 changes: 4 additions & 7 deletions
11
src/main/java/org/websoso/WSSServer/dto/auth/AppleLoginRequest.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 |
---|---|---|
@@ -1,14 +1,11 @@ | ||
package org.websoso.WSSServer.dto.auth; | ||
|
||
import jakarta.annotation.Nullable; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Pattern; | ||
|
||
public record AppleLoginRequest( | ||
@NotBlank(message = "사용자 고유 식별자는 null 이거나, 공백일 수 없습니다.") | ||
String userIdentifier, | ||
@Pattern(regexp = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,6}$", message = "이메일 형식이 올바르지 않습니다.") | ||
@Nullable | ||
String email | ||
@NotBlank(message = "애플 인증 코드 값은 null 이거나, 공백일 수 없습니다.") | ||
String authorizationCode, | ||
@NotBlank(message = "애플 ID 토큰 값은 null 이거나, 공백일 수 없습니다.") | ||
String idToken | ||
) { | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/org/websoso/WSSServer/dto/auth/ApplePublicKey.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,37 @@ | ||
package org.websoso.WSSServer.dto.auth; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record ApplePublicKey( | ||
String kty, | ||
String kid, | ||
String use, | ||
String alg, | ||
String n, | ||
String e | ||
) { | ||
|
||
public boolean isSameAlg(final String alg) { | ||
return this.alg.equals(alg); | ||
} | ||
|
||
public boolean isSameKid(final String kid) { | ||
return this.kid.equals(kid); | ||
} | ||
|
||
@JsonCreator | ||
public ApplePublicKey(@JsonProperty("kty") final String kty, | ||
@JsonProperty("kid") final String kid, | ||
@JsonProperty("use") final String use, | ||
@JsonProperty("alg") final String alg, | ||
@JsonProperty("n") final String n, | ||
@JsonProperty("e") final String e) { | ||
this.kty = kty; | ||
this.kid = kid; | ||
this.use = use; | ||
this.alg = alg; | ||
this.n = n; | ||
this.e = e; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/websoso/WSSServer/dto/auth/ApplePublicKeys.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,18 @@ | ||
package org.websoso.WSSServer.dto.auth; | ||
|
||
import static org.websoso.WSSServer.exception.error.CustomAppleLoginError.INVALID_APPLE_KEY; | ||
|
||
import java.util.List; | ||
import org.websoso.WSSServer.exception.exception.CustomAppleLoginException; | ||
|
||
public record ApplePublicKeys( | ||
List<ApplePublicKey> keys | ||
) { | ||
|
||
public ApplePublicKey getMatchingKey(final String alg, final String kid) { | ||
return keys.stream() | ||
.filter(key -> key.isSameAlg(alg) && key.isSameKid(kid)) | ||
.findFirst() | ||
.orElseThrow(() -> new CustomAppleLoginException(INVALID_APPLE_KEY, "invalid apple key")); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/websoso/WSSServer/dto/auth/AppleTokenResponse.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,23 @@ | ||
package org.websoso.WSSServer.dto.auth; | ||
|
||
public record AppleTokenResponse( | ||
String access_token, | ||
String expires_in, | ||
String id_token, | ||
String refresh_token, | ||
String token_type, | ||
String error | ||
) { | ||
|
||
public String getAccessToken() { | ||
return access_token; | ||
} | ||
|
||
public String getIdToken() { | ||
return id_token; | ||
} | ||
|
||
public String getRefreshToken() { | ||
return refresh_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
Oops, something went wrong.