omniauth-feishu 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d7bef3b09e1ac850ed6010582efdfb2fb6751279f6e86ab1cfbc55f1ad60eb6f
4
+ data.tar.gz: 4200cef9f0e4d3801e45331b6dec4579e57e4abe8ae6b5c42ef30994918ed35c
5
+ SHA512:
6
+ metadata.gz: 3b12f3b0768c268d351ce9edf8eae01abed9d4300a3f46add1336d8a0f7e085338959dd253d61e1e0645f571b29c1f116dd6b5a5129ad38e695bf587d7c4b14a
7
+ data.tar.gz: fa41d87117206a3b5a15bccc8e9b4c701c7c4819260b642e93f451540f8608431a7f36f55d86d4f172580bf23a81e9e8a26be0cfda7394dada2e89417ba2ca29
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-feishu.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,36 @@
1
+ # Omniauth::Feishu
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omniauth/feishu`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'omniauth-feishu'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install omniauth-feishu
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/omniauth-feishu.
36
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth/feishu"
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__)
@@ -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
@@ -0,0 +1,8 @@
1
+ require "omniauth/feishu/version"
2
+
3
+ module Omniauth
4
+ module Feishu
5
+ class Error < StandardError; end
6
+
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Feishu
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,72 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Feishu < OmniAuth::Strategies::OAuth2
6
+ class NoAppAccessTokenError < StandardError; end
7
+
8
+ attr_reader :app_access_token
9
+
10
+ option :name, 'feishu'
11
+
12
+ option :client_options, {
13
+ site: 'https://open.feishu.cn',
14
+ authorize_url: "/open-apis/authen/v1/user_auth_page_beta",
15
+ token_url: "https://open.feishu.cn/open-apis/authen/v1/access_token",
16
+ app_access_token_url: "https://open.feishu.cn/open-apis/auth/v3/app_access_token/internal",
17
+ user_info_url: "https://open.feishu.cn/open-apis/authen/v1/user_info"
18
+ }
19
+
20
+ info do
21
+ {
22
+ name: raw_info['name'],
23
+ email: raw_info['email'],
24
+ mobile: raw_info['mobile']
25
+ }
26
+ end
27
+
28
+ def raw_info
29
+ @raw_info ||= begin
30
+ response = Faraday.get(
31
+ options.client_options.user_info_url,
32
+ nil,
33
+ content_type: 'application/json', authorization: "Bearer #{access_token.token}"
34
+ )
35
+ response_body = JSON.parse(response.body)
36
+ response_body['data']
37
+ end
38
+ end
39
+
40
+ def build_access_token
41
+ resp = Faraday.post(
42
+ options.client_options.token_url,
43
+ { code: request.params["code"], app_access_token: app_access_token, grant_type: "authorization_code" }.to_json,
44
+ content_type: "application/json"
45
+ )
46
+ data = JSON.parse(resp.body)['data']
47
+ ::OAuth2::AccessToken.from_hash(client, data)
48
+ end
49
+
50
+ def callback_phase
51
+ get_app_access_token
52
+ super
53
+ end
54
+
55
+ private
56
+
57
+ def get_app_access_token
58
+ resp = Faraday.post(
59
+ options.client_options.app_access_token_url,
60
+ { app_id: options.client_id, app_secret: options.client_secret }.to_json,
61
+ content_type: "application/json"
62
+ )
63
+ response_body = JSON.parse(resp.body)
64
+ if response_body.key?('app_access_token')
65
+ @app_access_token = response_body['app_access_token']
66
+ else
67
+ raise NoAppAccessTokenError, "cannot get app_access_token."
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'lib/omniauth/feishu/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "omniauth-feishu"
5
+ spec.version = Omniauth::Feishu::VERSION
6
+ spec.authors = ["Renny"]
7
+ spec.email = ["rennyallen@hotmail.com"]
8
+
9
+ spec.summary = "Lark(Feishu) OAuth2 Strategy for OmniAuth"
10
+ spec.homepage = "https://github.com/renny-ren/omniauth-feishu"
11
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
+ spec.license = "MIT"
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-feishu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Renny
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - rennyallen@hotmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - README.md
23
+ - Rakefile
24
+ - bin/console
25
+ - bin/setup
26
+ - lib/omniauth/feishu.rb
27
+ - lib/omniauth/feishu/version.rb
28
+ - lib/omniauth/strategies/feishu.rb
29
+ - omniauth-feishu.gemspec
30
+ homepage: https://github.com/renny-ren/omniauth-feishu
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.3.0
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.0.8
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Lark(Feishu) OAuth2 Strategy for OmniAuth
53
+ test_files: []