Skip to content

Commit

Permalink
Merge branch 'main' into feat/board
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaktmchl committed Nov 6, 2022
2 parents 8e54765 + 42cdba5 commit d188228
Show file tree
Hide file tree
Showing 18 changed files with 1,289 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ plugins {

group = 'com.yogit'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
sourceCompatibility = '17'
targetCompatibility = '17'

configurations {
compileOnly {
Expand Down Expand Up @@ -37,8 +38,26 @@ dependencies {

// JWT
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'

// apple login
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' // 테스트 용
implementation 'org.apache.httpcomponents:httpclient'
implementation 'com.nimbusds:nimbus-jose-jwt:3.10'
implementation "io.jsonwebtoken:jjwt:0.9.1"
implementation "org.bouncycastle:bcpkix-jdk15on:1.50"
implementation "org.apache.httpcomponents:httpclient:4.5.13"
implementation fileTree(dir: 'libs', include: '*.jar')
}

tasks.named('test') {
useJUnitPlatform()
}

// apple login
tasks.withType(JavaCompile){
options.compilerArgs.addAll([
"--add-exports=java.base/sun.security.pkcs=ALL-UNNAMED",
"--add-exports=java.base/sun.security.util=ALL-UNNAMED",
"--add-exports=java.base/sun.security.x509=ALL-UNNAMED"
])
}
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());
}

}
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 server/src/main/java/com/yogit/server/applelogin/model/Key.java
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 server/src/main/java/com/yogit/server/applelogin/model/Keys.java
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() {
}
}
Loading

0 comments on commit d188228

Please sign in to comment.