omniauth-huawei 0.0.1
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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +28 -0
- data/Rakefile +1 -0
- data/Readme_CN.md +35 -0
- data/lib/omniauth-huawei.rb +2 -0
- data/lib/omniauth-huawei/version.rb +5 -0
- data/lib/omniauth/strategies/huawei.rb +60 -0
- data/omniauth-huawei.gemspec +23 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 834d8dceee88d3c5259d8ee12b8f6c787b5b966437d70ecd1e913d16edb80a9d
|
4
|
+
data.tar.gz: f05767e5cd449559ba5f8191ad76335289e32cc3eb043ba04d257fee578677c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f624c0f12775319ba684cac87a8be583cc0d9cc79c6e7c04cb59ee42413217bfe9c06c78ca1e8dc8dc7dd3cc23650f2e17795728065888a8d9ef89e2937a0a49
|
7
|
+
data.tar.gz: b965925e299450e1c81cb30f2540c7c543e8e3cf283a155b1f4f602401c861650677d4d3668783e01c79ac15bde9da7d8ba49375dac66277ac21db5bc73ad1ab
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 梁英豪
|
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,28 @@
|
|
1
|
+
# Omniauth::Huawei
|
2
|
+
|
3
|
+
oauth2 for https://developer.huawei.com/
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'omniauth-huawei', git: 'https://github.com/Heroesliang/omniauth-huawei.git'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install omniauth-huawei
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
|
22
|
+
## Contributing
|
23
|
+
|
24
|
+
1. Fork it
|
25
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
26
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
27
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
28
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/Readme_CN.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Omniauth::Huawei
|
2
|
+
|
3
|
+
Huawei 的 Omniauth 登录Gem包。
|
4
|
+
|
5
|
+
# 代码仓库
|
6
|
+
|
7
|
+
码云 https://gitee.com/HeroesLiang/omniauth-huawei
|
8
|
+
|
9
|
+
Github https://github.com/Heroesliang/omniauth-huawei
|
10
|
+
|
11
|
+
## 安装
|
12
|
+
|
13
|
+
在 Gemfile 添加:
|
14
|
+
|
15
|
+
gem 'omniauth-huawei', git: 'https://gitee.com/HeroesLiang/omniauth-huawei.git'
|
16
|
+
|
17
|
+
执行:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
或者使用 gem 命令直接安装:
|
22
|
+
|
23
|
+
$ gem install omniauth-huawei
|
24
|
+
|
25
|
+
## 使用
|
26
|
+
|
27
|
+
配置 Omniauth 即可
|
28
|
+
|
29
|
+
## 贡献
|
30
|
+
|
31
|
+
1. Fork本项目
|
32
|
+
2. 创建你的开发分支 (`git checkout -b my-new-feature`)
|
33
|
+
3. 将改动提交 (`git commit -am 'Add some feature'`)
|
34
|
+
4. 推送到分支上 (`git push origin my-new-feature`)
|
35
|
+
5. 创建 PullRequest
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
require 'jwt'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Huawei < OmniAuth::Strategies::OAuth2
|
7
|
+
option :client_options, {
|
8
|
+
:site => 'https://oauth-login.cloud.huawei.com',
|
9
|
+
:authorize_url => 'https://oauth-login.cloud.huawei.com/oauth2/v3/authorize?access_type=offline&scope=openid+profile',
|
10
|
+
:token_url => 'https://oauth-login.cloud.huawei.com/oauth2/v3/token'
|
11
|
+
}
|
12
|
+
|
13
|
+
def request_phase
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def authorize_params
|
18
|
+
super.tap do |params|
|
19
|
+
%w[scope client_options].each do |v|
|
20
|
+
if request.params[v]
|
21
|
+
params[v.to_sym] = request.params[v]
|
22
|
+
# to support omniauth-oauth2's auto csrf protection
|
23
|
+
session['omniauth.state'] = params[:state] if v == 'state'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
uid { raw_info['sub'].to_s }
|
30
|
+
|
31
|
+
info do
|
32
|
+
{
|
33
|
+
'name' => raw_info['display_name'],
|
34
|
+
'image' => raw_info['picture'],
|
35
|
+
'email' => raw_info['email']
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
extra do
|
40
|
+
{:raw_info => raw_info}
|
41
|
+
end
|
42
|
+
|
43
|
+
def raw_info
|
44
|
+
id_token = access_token.params['id_token']
|
45
|
+
# 验证失败会500,成功返回json格式的数据
|
46
|
+
@raw_info ||= JWT.decode(id_token, nil, false,
|
47
|
+
verify_iss: true,
|
48
|
+
iss: 'https://accounts.huawei.com',
|
49
|
+
verify_aud: true,
|
50
|
+
aud: options.client_id,
|
51
|
+
verify_expiration: true).first
|
52
|
+
rescue
|
53
|
+
# 本地验证失败后,向华为的服务器发起验证请求,返回json格式的数据
|
54
|
+
@raw_info ||= access_token.get("/oauth2/v3/tokeninfo?id_token=#{id_token}").parsed
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
OmniAuth.config.add_camelization 'huawei', 'Huawei'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth-huawei/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'omniauth-huawei'
|
8
|
+
spec.authors = ['liangyinghao']
|
9
|
+
spec.email = ['lyh1208401418@gmail.com']
|
10
|
+
spec.version = Omniauth::Huawei::VERSION
|
11
|
+
spec.description = %q{Oauth2 Gem for huawei.com}
|
12
|
+
spec.summary = %q{Oauth2 Gem for huawei.com}
|
13
|
+
spec.homepage = 'https://gitee.com'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-huawei
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- liangyinghao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-03 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Oauth2 Gem for huawei.com
|
42
|
+
email:
|
43
|
+
- lyh1208401418@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- Readme_CN.md
|
53
|
+
- lib/omniauth-huawei.rb
|
54
|
+
- lib/omniauth-huawei/version.rb
|
55
|
+
- lib/omniauth/strategies/huawei.rb
|
56
|
+
- omniauth-huawei.gemspec
|
57
|
+
homepage: https://gitee.com
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.1.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Oauth2 Gem for huawei.com
|
80
|
+
test_files: []
|