omniauth-kakao-oauth2 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bdb7d8c8577bf0111c0a068980a2f294443a66b758c45a6b07f745a99c108baa
4
+ data.tar.gz: d0c1b17d0aa0f5f28d323d76eabe40e87f3342780548b9a1d8eece6f939fbb5d
5
+ SHA512:
6
+ metadata.gz: 9a0012e1303940ef9b98444a448c3c2f095ad1187e489f756615e115c346ff1541e2158f7ab2d3ad58cd7dacf485a89412280f129888559080b1b1985c37b108
7
+ data.tar.gz: 1e109ce2e2b817bb863613f6a5b300ff104c7578eba88020bf4376bd8ff7ab06808d0ff325141e6272f79ff98015969478a4c25fed8b70caef52fddd58f1d595
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "build gem",
6
+ "type": "shell",
7
+ "command": "bundle exec rake build",
8
+ "group": "build",
9
+ "problemMatcher": [],
10
+ "isBackground": false
11
+ }
12
+ ]
13
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0] - 2025-08-04
4
+
5
+ ### Added
6
+ - Initial release of omniauth-kakao-oauth2
7
+ - Standard OmniAuth OAuth2 strategy for Kakao authentication
8
+ - Proper client_secret handling in request body (not headers)
9
+ - Support for Kakao profile scopes: profile_nickname, profile_image, account_email
10
+ - Comprehensive user information extraction
11
+ - Modern Ruby 3.1+ support
12
+ - Full test coverage
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 GoCoder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # OmniAuth Kakao OAuth2
2
+
3
+ 카카오 인증을 위한 올바른 OmniAuth OAuth2 strategy를 제공하는 Ruby gem입니다. 카카오 API 명세에 따라, `client_secret`을 헤더가 아닌 요청 본문에 포함합니다.
4
+
5
+
6
+ ## 설치
7
+ ```shell
8
+ gem install omniauth-kakao-oauth2
9
+ ```
10
+
11
+ ## 사용법
12
+
13
+ ### Rails 설정
14
+
15
+ ```ruby
16
+ # config/initializers/omniauth.rb
17
+ Rails.application.config.middleware.use OmniAuth::Builder do
18
+ # 기본
19
+ provider :kakao, ENV['KAKAO_CLIENT_ID']
20
+
21
+ # + Options
22
+ provider :kakao, ENV['KAKAO_CLIENT_ID'], {
23
+ scope: 'profile_nickname,profile_image,account_email',
24
+ redirect_url: 'http://localhost:3000/auth/kakao/callback'
25
+ }
26
+
27
+ # + Client Secret
28
+ provider :kakao, ENV['KAKAO_CLIENT_ID'], ENV['KAKAO_CLIENT_SECRET']
29
+
30
+ # + Client Secret & Options
31
+ provider :kakao, ENV['KAKAO_CLIENT_ID'], ENV['KAKAO_CLIENT_SECRET'], {
32
+ scope: 'profile_nickname,profile_image,account_email',
33
+ redirect_url: 'http://localhost:3000/auth/kakao/callback'
34
+ }
35
+
36
+ end
37
+ ```
38
+
39
+
40
+ ### 인증 해시
41
+
42
+ ```ruby
43
+ # request.env['omniauth.auth']
44
+ {
45
+ provider: 'kakao',
46
+ uid: '123456789',
47
+ info: {
48
+ name: 'John Doe',
49
+ username: 'john@example.com', # 이메일이 username으로도 제공됨
50
+ email: 'john@example.com',
51
+ image: 'https://...',
52
+ nickname: 'johndoe'
53
+ },
54
+ credentials: {
55
+ token: 'ACCESS_TOKEN',
56
+ expires_at: 1234567890,
57
+ expires: true
58
+ },
59
+ extra: {
60
+ raw_info: { ... },
61
+ kakao_account: { ... },
62
+ properties: { ... }
63
+ }
64
+ }
65
+ ```
66
+
67
+
68
+ ## Contribute
69
+
70
+ 버그 신고와 PR은 https://github.com/GoCoder7/omniauth-kakao-oauth2 로 부탁드립니다.
71
+
72
+
73
+ ## License
74
+
75
+ [MIT](https://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
data/example/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # Example Usage of omniauth-kakao-oauth2
2
+
3
+ This directory contains a simple example demonstrating how to use the omniauth-kakao-oauth2 gem in a Rails application.
4
+
5
+ ## Setup
6
+
7
+ 1. **Install the gem locally:**
8
+ ```bash
9
+ cd ..
10
+ bundle exec rake install
11
+ ```
12
+
13
+ 2. **Create a new Rails app:**
14
+ ```bash
15
+ rails new kakao_auth_example
16
+ cd kakao_auth_example
17
+ ```
18
+
19
+ 3. **Add to Gemfile:**
20
+ ```ruby
21
+ gem 'omniauth-kakao-oauth2'
22
+ gem 'omniauth-rails_csrf_protection'
23
+ ```
24
+
25
+ 4. **Configure OmniAuth (config/initializers/omniauth.rb):**
26
+ ```ruby
27
+ Rails.application.config.middleware.use OmniAuth::Builder do
28
+ # client_secret 없이 사용 (기본) | Without client_secret (basic)
29
+ provider :kakao, ENV['KAKAO_CLIENT_ID']
30
+
31
+ # client_secret과 함께 사용 | With client_secret
32
+ provider :kakao, ENV['KAKAO_CLIENT_ID'], ENV['KAKAO_CLIENT_SECRET']
33
+
34
+ # 옵션과 함께 사용 | With options
35
+ provider :kakao,
36
+ ENV['KAKAO_CLIENT_ID'],
37
+ ENV['KAKAO_CLIENT_SECRET'], # optional
38
+ {
39
+ scope: 'profile_nickname,profile_image,account_email',
40
+ redirect_url: 'http://localhost:3000/auth/kakao/callback'
41
+ }
42
+ end
43
+ ```
44
+
45
+ 5. **Add routes (config/routes.rb):**
46
+ ```ruby
47
+ get '/auth/:provider/callback', to: 'sessions#omniauth'
48
+ ```
49
+
50
+ 6. **Add controller (app/controllers/sessions_controller.rb):**
51
+ ```ruby
52
+ class SessionsController < ApplicationController
53
+ def omniauth
54
+ auth = request.env['omniauth.auth']
55
+ render json: {
56
+ provider: auth.provider,
57
+ uid: auth.uid,
58
+ info: auth.info,
59
+ credentials: auth.credentials
60
+ }
61
+ end
62
+ end
63
+ ```
64
+
65
+ ## Testing
66
+
67
+ Navigate to `http://localhost:3000/auth/kakao` to start the authentication flow.
68
+
69
+ ## Expected Response
70
+
71
+ ```json
72
+ {
73
+ "provider": "kakao",
74
+ "uid": "123456789",
75
+ "info": {
76
+ "name": "John Doe",
77
+ "username": "john@example.com",
78
+ "email": "john@example.com",
79
+ "image": "https://...",
80
+ "nickname": "johndoe"
81
+ },
82
+ "credentials": {
83
+ "token": "ACCESS_TOKEN",
84
+ "expires_at": 1234567890,
85
+ "expires": true
86
+ }
87
+ }
88
+ ```
@@ -0,0 +1,78 @@
1
+ # Rails Integration Example for omniauth-kakao-oauth2
2
+ # Rails에서 omniauth-kakao-oauth2 사용 예제
3
+
4
+ # Gemfile에 추가 | Add to Gemfile
5
+ # gem 'omniauth-kakao-oauth2'
6
+ # gem 'omniauth-rails_csrf_protection'
7
+
8
+ # config/initializers/omniauth.rb
9
+ Rails.application.config.middleware.use OmniAuth::Builder do
10
+ # 기본 사용법 (client_secret 없이) | Basic usage (without client_secret)
11
+ provider :kakao, ENV['KAKAO_CLIENT_ID']
12
+
13
+ # client_secret과 함께 사용 | With client_secret
14
+ provider :kakao, ENV['KAKAO_CLIENT_ID'], ENV['KAKAO_CLIENT_SECRET']
15
+
16
+ # 옵션과 함께 사용 | With options
17
+ provider :kakao, ENV['KAKAO_CLIENT_ID'], ENV['KAKAO_CLIENT_SECRET'], {
18
+ scope: 'profile_nickname,profile_image,account_email',
19
+ redirect_url: 'http://localhost:3000/auth/kakao/callback'
20
+ }
21
+ end
22
+
23
+ # config/routes.rb
24
+ Rails.application.routes.draw do
25
+ get '/auth/kakao/callback', to: 'sessions#omniauth'
26
+ # 기타 라우트들...
27
+ end
28
+
29
+ # app/controllers/sessions_controller.rb
30
+ class SessionsController < ApplicationController
31
+ def omniauth
32
+ auth = request.env['omniauth.auth']
33
+
34
+ # 사용자 찾기 또는 생성 | Find or create user
35
+ user = User.find_or_create_by(uid: auth.uid, provider: auth.provider) do |u|
36
+ u.name = auth.info.name
37
+ u.username = auth.info.username # 이메일이 username으로도 제공됨
38
+ u.email = auth.info.email
39
+ u.image = auth.info.image
40
+ u.nickname = auth.info.nickname
41
+ end
42
+
43
+ if user.persisted?
44
+ session[:user_id] = user.id
45
+ redirect_to root_path, notice: '카카오 로그인이 완료되었습니다!'
46
+ else
47
+ redirect_to login_path, alert: '로그인 중 오류가 발생했습니다.'
48
+ end
49
+ end
50
+ end
51
+
52
+ # app/models/user.rb
53
+ class User < ApplicationRecord
54
+ validates :uid, presence: true
55
+ validates :provider, presence: true
56
+ validates :email, presence: true, uniqueness: true
57
+
58
+ def self.from_kakao_omniauth(auth)
59
+ where(uid: auth.uid, provider: auth.provider).first_or_create! do |user|
60
+ user.name = auth.info.name
61
+ user.username = auth.info.username
62
+ user.email = auth.info.email
63
+ user.image = auth.info.image
64
+ user.nickname = auth.info.nickname
65
+ end
66
+ end
67
+ end
68
+
69
+ # 마이그레이션 예제 | Migration example
70
+ # rails generate migration CreateUsers uid:string provider:string name:string username:string email:string image:string nickname:string
71
+ # rails db:migrate
72
+
73
+ # 환경 변수 설정 예제 (.env 파일)
74
+ # KAKAO_CLIENT_ID=your_kakao_rest_api_key
75
+ # KAKAO_CLIENT_SECRET=your_kakao_client_secret # optional
76
+
77
+ # 뷰 예제 | View example
78
+ # <%= link_to "카카오로 로그인", "/auth/kakao", method: :post, class: "btn btn-warning" %>
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omniauth
4
+ module Kakao
5
+ module Oauth2
6
+ VERSION = "1.0.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "oauth2/version"
4
+ require_relative "../strategies/kakao_oauth2"
5
+
6
+ module Omniauth
7
+ module Kakao
8
+ module Oauth2
9
+ class Error < StandardError; end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth-oauth2"
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ # OmniAuth OAuth2 strategy for Kakao authentication
8
+ # This strategy properly handles client_secret in the request body as required by Kakao's API
9
+ class KakaoOauth2 < OmniAuth::Strategies::OAuth2
10
+ option :name, :kakao
11
+
12
+ option :client_options,
13
+ site: "https://kauth.kakao.com",
14
+ authorize_url: "/oauth/authorize",
15
+ token_url: "/oauth/token"
16
+
17
+ option :scope, "profile_nickname,profile_image"
18
+
19
+ # User ID from Kakao
20
+ uid { raw_info["id"].to_s }
21
+
22
+ # User information mapping
23
+ info do
24
+ {
25
+ name: raw_info.dig("properties", "nickname"),
26
+ username: kakao_email, # 이메일을 username으로도 제공
27
+ email: kakao_email,
28
+ image: raw_info.dig("properties", "profile_image") || raw_info.dig("properties", "thumbnail_image"),
29
+ nickname: raw_info.dig("properties", "nickname")
30
+ }
31
+ end
32
+
33
+ # Extra information (sb-omniauth-kakao 호환성을 위해 properties 추가)
34
+ extra do
35
+ {
36
+ raw_info: raw_info,
37
+ kakao_account: raw_info["kakao_account"],
38
+ properties: raw_info["properties"] # sb-omniauth-kakao 호환성
39
+ }
40
+ end
41
+
42
+ # Override to include client_secret in request body instead of header
43
+ def build_access_token
44
+ verifier = request.params["code"]
45
+
46
+ # Build token parameters with optional client_secret in the body
47
+ token_params = {
48
+ redirect_uri: callback_url,
49
+ client_id: options.client_id,
50
+ grant_type: "authorization_code"
51
+ }
52
+
53
+ # Include client_secret only if provided (optional parameter)
54
+ token_params[:client_secret] = options.client_secret if options.client_secret
55
+
56
+ # Merge any additional token parameters
57
+ token_params.merge!(options.token_params || {})
58
+
59
+ client.auth_code.get_token(verifier, token_params, deep_symbolize(options.auth_token_params || {}))
60
+ end
61
+
62
+ private
63
+
64
+ # Get user information from Kakao API
65
+ def raw_info
66
+ @raw_info ||= access_token.get("https://kapi.kakao.com/v2/user/me").parsed
67
+ end
68
+
69
+ # Extract email if available and verified
70
+ def kakao_email
71
+ account = raw_info["kakao_account"]
72
+ return nil unless account
73
+
74
+ if account["has_email"] && account["is_email_verified"] && account["is_email_valid"]
75
+ account["email"]
76
+ end
77
+ end
78
+
79
+ # Callback URL for OAuth flow (redirect_url 옵션 지원)
80
+ def callback_url
81
+ options.redirect_url || options.redirect_path || (full_host + callback_path)
82
+ end
83
+
84
+ # Deep symbolize hash keys (from omniauth-oauth2)
85
+ def deep_symbolize(options)
86
+ options.each_with_object({}) do |(key, value), hash|
87
+ hash[key.to_sym] = value.is_a?(Hash) ? deep_symbolize(value) : value
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ # Register the strategy with OmniAuth
95
+ OmniAuth.config.add_camelization "kakao", "KakaoOauth2"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "omniauth/kakao/oauth2"
@@ -0,0 +1,8 @@
1
+ module Omniauth
2
+ module Kakao
3
+ module Oauth2
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-kakao-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - GoCoder
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: omniauth
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: omniauth-oauth2
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.8'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.8'
40
+ - !ruby/object:Gem::Dependency
41
+ name: bundler
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '13.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: minitest
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '5.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '5.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rubocop
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.21'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.21'
96
+ description: A Ruby gem providing OmniAuth OAuth2 strategy for Kakao authentication.
97
+ Unlike other Kakao OAuth gems, this properly includes client_secret in the request
98
+ body as required by Kakao's API specification.
99
+ email:
100
+ - gocoder7@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".rubocop.yml"
106
+ - ".vscode/tasks.json"
107
+ - CHANGELOG.md
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - example/README.md
112
+ - examples/rails_integration.rb
113
+ - lib/omniauth-kakao-oauth2.rb
114
+ - lib/omniauth/kakao/oauth2.rb
115
+ - lib/omniauth/kakao/oauth2/version.rb
116
+ - lib/omniauth/strategies/kakao_oauth2.rb
117
+ - sig/omniauth/kakao/oauth2.rbs
118
+ homepage: https://github.com/GoCoder7/omniauth-kakao-oauth2
119
+ licenses:
120
+ - MIT
121
+ metadata:
122
+ allowed_push_host: https://rubygems.org
123
+ homepage_uri: https://github.com/GoCoder7/omniauth-kakao-oauth2
124
+ source_code_uri: https://github.com/GoCoder7/omniauth-kakao-oauth2
125
+ changelog_uri: https://github.com/GoCoder7/omniauth-kakao-oauth2/blob/main/CHANGELOG.md
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 3.1.0
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubygems_version: 3.6.9
141
+ specification_version: 4
142
+ summary: OmniAuth OAuth2 strategy for Kakao with proper client_secret handling
143
+ test_files: []