-
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.
- Loading branch information
Showing
18 changed files
with
1,289 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
147 changes: 147 additions & 0 deletions
147
server/src/main/java/com/yogit/server/applelogin/controller/AppleController.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,147 @@ | ||
package com.yogit.server.applelogin.controller; | ||
|
||
import com.yogit.server.applelogin.model.AppsResponse; | ||
import com.yogit.server.applelogin.model.ServicesResponse; | ||
import com.yogit.server.applelogin.model.TokenResponse; | ||
import com.yogit.server.applelogin.service.AppleService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Map; | ||
|
||
@Controller | ||
public class AppleController { | ||
|
||
private Logger logger = LoggerFactory.getLogger(AppleController.class); | ||
|
||
@Autowired | ||
AppleService appleService; | ||
|
||
/** | ||
* Sign in with Apple - JS Page (index.html) | ||
* | ||
* @param model | ||
* @return | ||
*/ | ||
@GetMapping(value = "/") | ||
public String appleLoginPage(ModelMap model) { | ||
|
||
Map<String, String> metaInfo = appleService.getLoginMetaInfo(); | ||
|
||
model.addAttribute("client_id", metaInfo.get("CLIENT_ID")); | ||
model.addAttribute("redirect_uri", metaInfo.get("REDIRECT_URI")); | ||
model.addAttribute("nonce", metaInfo.get("NONCE")); | ||
|
||
System.out.println(model.getAttribute("client_id")); | ||
System.out.println(model.getAttribute("redirect_uri")); | ||
System.out.println(model.getAttribute("nonce")); | ||
|
||
|
||
return "index"; | ||
} | ||
|
||
/** | ||
* Apple login page Controller (SSL - https) | ||
* | ||
* @param model | ||
* @return | ||
*/ | ||
@GetMapping(value = "/apple/login") | ||
public String appleLogin(ModelMap model) { | ||
|
||
Map<String, String> metaInfo = appleService.getLoginMetaInfo(); | ||
|
||
model.addAttribute("client_id", metaInfo.get("CLIENT_ID")); | ||
model.addAttribute("redirect_uri", metaInfo.get("REDIRECT_URI")); | ||
model.addAttribute("nonce", metaInfo.get("NONCE")); | ||
model.addAttribute("response_type", "code id_token"); | ||
model.addAttribute("scope", "name email"); | ||
model.addAttribute("response_mode", "form_post"); | ||
|
||
System.out.println("=========================="); | ||
System.out.println(model.getAttribute("client_id")); | ||
System.out.println(model.getAttribute("redirect_uri")); | ||
System.out.println(model.getAttribute("nonce")); | ||
System.out.println(model.getAttribute("response_type")); | ||
System.out.println(model.getAttribute("scope")); | ||
System.out.println(model.getAttribute("response_mode")); | ||
|
||
|
||
return "redirect:https://appleid.apple.com/auth/authorize"; | ||
} | ||
|
||
/** | ||
* Apple Login 유저 정보를 받은 후 권한 생성 | ||
* | ||
* @param serviceResponse | ||
* @return | ||
*/ | ||
@PostMapping(value = "/redirect") | ||
@ResponseBody | ||
public TokenResponse servicesRedirect(ServicesResponse serviceResponse) throws NoSuchAlgorithmException { | ||
|
||
System.out.println("1-------------"); | ||
if (serviceResponse == null) { | ||
return null; | ||
} | ||
System.out.println("2-------------"); | ||
|
||
|
||
System.out.println(serviceResponse); | ||
System.out.println("3-------------"); | ||
|
||
|
||
String code = serviceResponse.getCode(); | ||
System.out.println(code); | ||
System.out.println("4-------------"); | ||
|
||
String id_token = serviceResponse.getId_token(); | ||
System.out.println(id_token); | ||
System.out.println("5-------------"); | ||
|
||
String client_secret = appleService.getAppleClientSecret(serviceResponse.getId_token()); | ||
System.out.println(client_secret); | ||
System.out.println("6-------------"); | ||
|
||
|
||
logger.debug("================================"); | ||
logger.debug("id_token ‣ " + serviceResponse.getId_token()); | ||
logger.debug("payload ‣ " + appleService.getPayload(serviceResponse.getId_token())); | ||
logger.debug("client_secret ‣ " + client_secret); | ||
logger.debug("================================"); | ||
|
||
System.out.println("7-------------"); | ||
|
||
return appleService.requestCodeValidations(client_secret, code, null); | ||
} | ||
|
||
/** | ||
* refresh_token 유효성 검사 | ||
* | ||
* @param client_secret | ||
* @param refresh_token | ||
* @return | ||
*/ | ||
@PostMapping(value = "/refresh") | ||
@ResponseBody | ||
public TokenResponse refreshRedirect(@RequestParam String client_secret, @RequestParam String refresh_token) { | ||
return appleService.requestCodeValidations(client_secret, null, refresh_token); | ||
} | ||
|
||
/** | ||
* Apple 유저의 이메일 변경, 서비스 해지, 계정 탈퇴에 대한 Notifications을 받는 Controller (SSL - https (default: 443)) | ||
* | ||
* @param appsResponse | ||
*/ | ||
@PostMapping(value = "/apps/to/endpoint") | ||
@ResponseBody | ||
public void appsToEndpoint(@RequestBody AppsResponse appsResponse) { | ||
logger.debug("[/path/to/endpoint] RequestBody ‣ " + appsResponse.getPayload()); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
server/src/main/java/com/yogit/server/applelogin/model/AppsResponse.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 com.yogit.server.applelogin.model; | ||
|
||
|
||
public class AppsResponse { | ||
|
||
private String payload; | ||
|
||
public String getPayload() { | ||
return payload; | ||
} | ||
|
||
public void setPayload(String payload) { | ||
this.payload = payload; | ||
} | ||
|
||
public AppsResponse() { | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
server/src/main/java/com/yogit/server/applelogin/model/Key.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,62 @@ | ||
package com.yogit.server.applelogin.model; | ||
|
||
public class Key { | ||
|
||
private String kty; | ||
private String kid; | ||
private String use; | ||
private String alg; | ||
private String n; | ||
private String e; | ||
|
||
public String getKty() { | ||
return kty; | ||
} | ||
|
||
public void setKty(String kty) { | ||
this.kty = kty; | ||
} | ||
|
||
public String getKid() { | ||
return kid; | ||
} | ||
|
||
public void setKid(String kid) { | ||
this.kid = kid; | ||
} | ||
|
||
public String getUse() { | ||
return use; | ||
} | ||
|
||
public void setUse(String use) { | ||
this.use = use; | ||
} | ||
|
||
public String getAlg() { | ||
return alg; | ||
} | ||
|
||
public void setAlg(String alg) { | ||
this.alg = alg; | ||
} | ||
|
||
public String getN() { | ||
return n; | ||
} | ||
|
||
public void setN(String n) { | ||
this.n = n; | ||
} | ||
|
||
public String getE() { | ||
return e; | ||
} | ||
|
||
public void setE(String e) { | ||
this.e = e; | ||
} | ||
|
||
public Key() { | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
server/src/main/java/com/yogit/server/applelogin/model/Keys.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,19 @@ | ||
package com.yogit.server.applelogin.model; | ||
|
||
import java.util.List; | ||
|
||
public class Keys { | ||
|
||
private List<Key> keys; | ||
|
||
public List<Key> getKeys() { | ||
return keys; | ||
} | ||
|
||
public void setKeys(List<Key> keys) { | ||
this.keys = keys; | ||
} | ||
|
||
public Keys() { | ||
} | ||
} |
Oops, something went wrong.