oauth2_dingtalk 0.1.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
+ SHA1:
3
+ metadata.gz: c00a42fb9bb9c5ecff9713c7b827daa8cd661c38
4
+ data.tar.gz: b44356d7e17ec7e28558049d323fd758c06a4d53
5
+ SHA512:
6
+ metadata.gz: dfee89dedf85a8d8036f252c11e18c6accdbef58702aacfcaeefee1d0cf6c376554ae55a826a0018e8217b5f45328626f94eab5ee59cd84117b4f4344df0dba9
7
+ data.tar.gz: 5c365212a5815b076f45ffeed9e58f9fb18d406eedf6d58fa194f98b36d64468a21b1a3f45569a2b4126982770b01a7041663f6a91721197bbf918207ccfe150
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ /example/.bundle/*
14
+ /example/Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in oauth2_dingtalk.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 LiuKun
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,36 @@
1
+ # Oauth2Dingtalk
2
+
3
+ 该 Gem 的主要是使用钉钉扫码登录 Gitlab。
4
+
5
+ ## Usage
6
+
7
+ 1. 和其他的 Oauth2 Gem 一样,在 Gemfile 里面添加:
8
+ ```
9
+ gem 'oauth2_dingtalk'
10
+ ```
11
+
12
+ 2. 然后在`config/initializers`里添加文件`dingding.rb`:
13
+
14
+ ```ruby
15
+ # config/initializers/dingding.rb
16
+ Rails.application.config.middleware.use OmniAuth::Builder do
17
+ provider :dingding, "Your_OAuth_App_ID", "Your_OAuth_App_Secret"
18
+ end
19
+ ```
20
+
21
+ 3. 然后可以看 example 文件里面的例子,如果是在 Rails 项目里面使用的话,可以在路由那边添加:
22
+
23
+ ```ruby
24
+ get '/auth/:provider/callback', 'sessions#create'
25
+ ```
26
+
27
+ 或者其他的方式。
28
+
29
+ 4. 最主要的是
30
+ ```
31
+ auth = request.env["omniauth.auth"]
32
+ auth["provider"] # dingding
33
+ auth["uid"] # 用户在当前开放应用内的唯一标识
34
+ ```
35
+
36
+ 可参考:http://railscasts.com/episodes/241-simple-omniauth?autoplay=true
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oauth2_dingtalk"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/example/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'sinatra'
4
+ gem 'multi_json'
5
+ gem 'oauth2_dingtalk'
data/example/config.ru ADDED
@@ -0,0 +1,33 @@
1
+ require 'bundler'
2
+ require 'sinatra'
3
+ require 'oauth2_dingtalk'
4
+
5
+ ENV['APPID'] = "APPID"
6
+ ENV['APPSECRET'] = "APPSECRET"
7
+
8
+ class App < Sinatra::Base
9
+ get '/' do
10
+ redirect '/auth/dingding'
11
+ end
12
+
13
+ get '/auth/:provider/callback' do
14
+ content_type 'application/json'
15
+ puts MultiJson.encode(request.env)
16
+ end
17
+
18
+ get '/auth/failure' do
19
+ content_type 'application/json'
20
+ MultiJson.encode(request.env)
21
+ end
22
+ end
23
+
24
+ use Rack::Session::Cookie, :secret => "change_me"
25
+
26
+ use OmniAuth::Builder do
27
+ # note that the scope is different from the default
28
+ # we also have to repeat the default fields in order to get
29
+ # the extra 'connections' field in there
30
+ provider :dingding, ENV['APPID'], ENV['APPSECRET']
31
+ end
32
+
33
+ run App.new
@@ -0,0 +1,3 @@
1
+ module Oauth2Dingtalk
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "oauth2_dingtalk/version"
2
+ require_relative "omniauth/strategies/dingding"
3
+
4
+ module Oauth2Dingtalk
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,56 @@
1
+ require "omniauth-oauth2"
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Dingding < OmniAuth::Strategies::OAuth2
6
+ option :name, "dingding"
7
+
8
+ option :client_options, {
9
+ site: "https://oapi.dingtalk.com",
10
+ authorize_url: "/connect/qrconnect",
11
+ token_url: "/sns/gettoken",
12
+ persistent_url: "/sns/get_persistent_code",
13
+ token_method: :get
14
+ }
15
+
16
+ option :authorize_params, { scope: 'snsapi_login' }
17
+
18
+ uid do
19
+ raw_info['openid']
20
+ end
21
+
22
+ info do
23
+ {
24
+ unionid: raw_info['unionid']
25
+ }
26
+ end
27
+
28
+ extra do
29
+ { raw_info: raw_info }
30
+ end
31
+
32
+ def request_phase
33
+ params = client.auth_code.authorize_params.merge(redirect_uri: callback_url).merge(authorize_params)
34
+ params["appid"] = params.delete("client_id")
35
+ redirect client.authorize_url(params)
36
+ end
37
+
38
+ def raw_info
39
+ @raw_info ||= access_token.post(options.client_options[:persistent_url] + "?access_token=#{access_token.token}") do |req|
40
+ req.headers['Content-Type'] = 'application/json'
41
+ req.body = "{\"tmp_auth_code\":\"#{request.params['code']}\"}"
42
+ end.parsed
43
+ end
44
+
45
+ protected
46
+
47
+ def build_access_token
48
+ params = {
49
+ 'appid' => client.id,
50
+ 'appsecret' => client.secret
51
+ }
52
+ client.get_token(params)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "oauth2_dingtalk/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "oauth2_dingtalk"
8
+ spec.version = Oauth2Dingtalk::VERSION
9
+ spec.authors = %w[liukun]
10
+ spec.email = %w[fee1mix@163.com]
11
+
12
+ spec.summary = 'Omniauth strategy for Dingding(alibaba)'
13
+ spec.description = 'Using OAuth2 to authenticate dingding user when web resources being viewed within dingding(alibaba) client.'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.15"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_dependency 'omniauth', '~> 1.0'
25
+ spec.add_dependency 'omniauth-oauth2', '~> 1.0'
26
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth2_dingtalk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - liukun
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: omniauth
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: omniauth-oauth2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description: Using OAuth2 to authenticate dingding user when web resources being viewed
84
+ within dingding(alibaba) client.
85
+ email:
86
+ - fee1mix@163.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - example/Gemfile
101
+ - example/config.ru
102
+ - lib/oauth2_dingtalk.rb
103
+ - lib/oauth2_dingtalk/version.rb
104
+ - lib/omniauth/strategies/dingding.rb
105
+ - oauth2_dingtalk.gemspec
106
+ homepage:
107
+ licenses: []
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.13
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Omniauth strategy for Dingding(alibaba)
129
+ test_files: []