Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ“ฎ ์นด์นด์˜ค Oauth ๊ตฌํ˜„ && ๋ฐฑ์—”๋“œ ์—ฐ๋™ #56

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

heejinnn
Copy link
Collaborator

@heejinnn heejinnn commented Jan 3, 2024

์ž‘์—… ์ด์œ 

๋ฐฑ์—”๋“œ์™€ ์—ฐ๋™ํ•˜์—ฌ kakao oauth๋ฅผ ์ฒ˜๋ฆฌํ•˜์˜€๋‹ค.

์ž‘์—… ์‚ฌํ•ญ

kakao oauth ๋™์ž‘ ๊ณผ์ •

  1. kakao ๋กœ๊ทธ์ธ
  2. ๊ธฐ์กด์— fit a pet์— ๋“ฑ๋ก๋œ ์‚ฌ์šฉ์ž๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ => ์ „ํ™”๋ฒˆํ˜ธ ์ธ์ฆ ํ›„ ํšŒ์›๊ฐ€์ž…
  3. ๊ธฐ์กด์— ๋“ฑ๋ก๋œ ์‚ฌ์šฉ์ž์ธ ๊ฒฝ์šฐ => ๋ฐ”๋กœ ๋กœ๊ทธ์ธ

  • nonce, id, phone, provider๋Š” ์ƒ์ˆ˜๋กœ ๊ด€๋ฆฌํ•˜์˜€๋‹ค.
enum OauthInfo{
    static var oauthId = 0
    static var phoneNum = ""
    static var nonce = ""
    static var provider = ""
}

  • idToken์€ KeyChain์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ด€๋ฆฌํ•˜์˜€๋‹ค.
static func saveTempToken(tempToken: String) {
    let passwordQuery: [CFString: Any] = [
        kSecClass: kSecClassGenericPassword,
        kSecAttrAccount: "tempToken",
        kSecValueData: tempToken.data(using: .utf8)!,
    ]
    
    let status = SecItemAdd(passwordQuery as CFDictionary, nil)
    if status == errSecDuplicateItem {
        SecItemUpdate(passwordQuery as CFDictionary, [kSecValueData: tempToken.data(using: .utf8)!] as CFDictionary)
    } else if status != noErr {
        print("Failed to save tempToken to Keychain")
    }
}

static func loadTempToken() -> String? {
    let query: [CFString: Any] = [
        kSecClass: kSecClassGenericPassword,
        kSecAttrAccount: "tempToken",
        kSecReturnData: kCFBooleanTrue!,
    ]

    var item: CFTypeRef?
    let status = SecItemCopyMatching(query as CFDictionary, &item)

    if status == noErr, let data = item as? Data, let token = String(data: data, encoding: .utf8) {
        return token
    } else {
        return nil
    }
}

1๏ธโƒฃ kakao ๋กœ๊ทธ์ธ

  • POST /api/v1/auth/oauth?provider={}
  • body: ["id": Int, "idToken": String, "nonce": String]
  • query: provider = [String]
  • header:
case .oauthLogin:
    let idToken = KeychainHelper.loadTempToken()!
    
    let bodyParameters = ["id": OauthInfo.oauthId, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any]
    let queryParameters = [URLQueryItem(name: "provider", value: OauthInfo.provider)]
    
    request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters)

2๏ธโƒฃ kakao oauth ์ธ์ฆ์ฝ”๋“œ ๋ฐœ์‹ 

  • POST /api/v1/auth/oauth/{oauthid}/sms?provider={}
  • body: ["to": String, "idToken": String, "nonce": String]
  • query: provider = [String]
  • header:
case .oauthSendSms:
    let idToken = KeychainHelper.loadTempToken()!
    
    let bodyParameters = ["to": OauthInfo.phoneNum, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any]
    let queryParameters = [URLQueryItem(name: "provider", value: OauthInfo.provider)]
    
    request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters)

3๏ธโƒฃ kakao oauth ์ธ์ฆ์ฝ”๋“œ ์ธ์ฆ

  • POST /api/v1/auth/oauth/{oauthid}/sms?provider={}&code={}
  • body: ["to": String, "idToken": String, "nonce": String]
  • query: provider = [String], code = [String]
  • header:
 case .oauthCheckSms(let code):
    let idToken = KeychainHelper.loadTempToken()!
    
    let bodyParameters = ["to": OauthInfo.phoneNum, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any]
    let queryParameters = [URLQueryItem(name: "provider", value: OauthInfo.provider), URLQueryItem(name: "code", value: code)]
    
    request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters)

4๏ธโƒฃ kakao oauth ํšŒ์›๊ฐ€์ž…

  • POST /api/v1/auth/oauth/{oauthid}?provider={}
  • body: ["name": String, "uid": String, "idToken": String, "nonce": String]
  • query: provider = [String]
  • header: accessToken
 case .oauthRegistUser(let name, let uid):
    let idToken = KeychainHelper.loadTempToken()!
    
    let bodyParameters = ["name": name, "uid": uid, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any]
    let queryParameters = [URLQueryItem(name: "provider", value: OauthInfo.provider)]
    
    if let accessToken = KeychainHelper.loadAccessToken() {
        request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters)
        request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
    } else {
        request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters)
    }

์ด์Šˆ ์—ฐ๊ฒฐ

#40
#12

@heejinnn heejinnn self-assigned this Jan 3, 2024
@psychology50
Copy link
Member

psychology50 commented Jan 4, 2024

15์‹œ 30๋ถ„์— ๋‹ค์‹œ ์ฝ์–ด๋ณด๊ณ  ์Šน์ธํ• ๊ฒŒ์š”

Copy link
Member

@psychology50 psychology50 left a comment

Choose a reason for hiding this comment

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

์˜ค๋Š˜ ์ €๋… ํšŒ์˜ ๋•Œ ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜๋Š” ๊ฑฐ ํ™•์ธํ•ด๋ณด๋ฉด ๋  ๊ฒƒ ๊ฐ™์•„์š”.
์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค.

@psychology50 psychology50 merged commit 10a544c into develop Jan 4, 2024
1 of 3 checks passed
@psychology50 psychology50 deleted the feat/40 branch January 4, 2024 06:25
@heejinnn heejinnn changed the title ์นด์นด์˜ค Oauth ๊ตฌํ˜„ && ๋ฐฑ์—”๋“œ ์—ฐ๋™ ๐Ÿ“ฎ ์นด์นด์˜ค Oauth ๊ตฌํ˜„ && ๋ฐฑ์—”๋“œ ์—ฐ๋™ Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants