omniauth-telegram 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 465c3fbe0a9c88a70981edee957770a1007081422170ff2c777bcc4ffe14da62
4
+ data.tar.gz: 5150f90bc2f80b73b156dbee37a1a209bb3a9a3de3e4d75e7d9ea542ca161ae7
5
+ SHA512:
6
+ metadata.gz: f6a0f7dfdabbb76797648501bb1ce650e3e9bd73a0568e65e767adbe5a2762051bf11a5b8c0e78260b31c47c67dccd1fb5acd94d8fb4d7389cee7bc110ba02cb
7
+ data.tar.gz: c2f76a11fa19e84033e5254bab6dd346fa6f21a54492089e2b3f79c12086a71668d4ca87ade6158bd0c531767bb3c44054b2db96c9ac3c914de87235711234dd
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.1
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 omniauth-telegram.gemspec
6
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-telegram (1.0.0)
5
+ omniauth (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ hashie (3.5.7)
12
+ omniauth (1.8.1)
13
+ hashie (>= 3.4.6, < 3.6.0)
14
+ rack (>= 1.6.2, < 3)
15
+ rack (2.0.5)
16
+ rake (10.5.0)
17
+ rspec (3.6.0)
18
+ rspec-core (~> 3.6.0)
19
+ rspec-expectations (~> 3.6.0)
20
+ rspec-mocks (~> 3.6.0)
21
+ rspec-core (3.6.0)
22
+ rspec-support (~> 3.6.0)
23
+ rspec-expectations (3.6.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.6.0)
26
+ rspec-mocks (3.6.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.6.0)
29
+ rspec-support (3.6.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.16)
36
+ omniauth-telegram!
37
+ rake (~> 10.0)
38
+ rspec (~> 3.0)
39
+
40
+ BUNDLED WITH
41
+ 1.16.1
@@ -0,0 +1,51 @@
1
+ # OmniAuth Telegram &nbsp;[![Build Status](https://secure.travis-ci.org/yurijmi/omniauth-telegram.svg?branch=master)](https://travis-ci.org/yurijmi/omniauth-telegram) [![Gem Version](https://img.shields.io/gem/v/omniauth-telegram.svg)](https://rubygems.org/gems/omniauth-telegram)
2
+
3
+ Telegram Strategy for OmniAuth. You'll need to setup a bot for Telegram first. [More info here](https://core.telegram.org/widgets/login)
4
+
5
+ ## Installing
6
+
7
+ Add to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'omniauth-telegram'
11
+ ```
12
+
13
+ Then `bundle install`.
14
+
15
+ ## Usage
16
+
17
+ `OmniAuth::Strategies::Telegram` is simply a Rack middleware. Read the OmniAuth docs for detailed instructions:
18
+ https://github.com/intridea/omniauth.
19
+
20
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
21
+
22
+ ```ruby
23
+ Rails.application.config.middleware.use OmniAuth::Builder do
24
+ provider :telegram, ENV['BOT_NAME'], ENV['BOT_SECRET']
25
+ end
26
+ ```
27
+
28
+ ## Configuring
29
+
30
+ You can customise the button (more info on telegram's api website):
31
+
32
+ ```ruby
33
+ Rails.application.config.middleware.use OmniAuth::Builder do
34
+ provider :telegram, ENV['BOT_NAME'], ENV['BOT_SECRET'],
35
+ button_options: { 'request-access' => 'write' }
36
+ end
37
+ ```
38
+
39
+ ## Supported Rubies
40
+
41
+ - Ruby MRI (2.0+)
42
+
43
+ ## License
44
+
45
+ Copyright (c) 2018 by Yuri Mikhaylov
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth/telegram"
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,94 @@
1
+ require 'omniauth'
2
+ require 'openssl'
3
+ require 'base64'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Telegram
8
+ include OmniAuth::Strategy
9
+
10
+ args [:bot_name, :bot_secret]
11
+
12
+ option :name, 'telegram'
13
+ option :bot_name, nil
14
+ option :bot_secret, nil
15
+ option :button_config, {}
16
+
17
+ FIELDS = %w[id first_name last_name username photo_url auth_date hash]
18
+ HASH_FIELDS = %w[auth_date first_name id last_name photo_url username]
19
+
20
+ def request_phase
21
+ html = <<-HTML
22
+ <!DOCTYPE html>
23
+ <html>
24
+ <head>
25
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
26
+ <title>Telegram Login</title>
27
+ </head>
28
+ <body>
29
+ HTML
30
+
31
+ data_attrs = options.button_config.map { |k,v| "data-#{k}=\"#{v}\"" }.join(" ")
32
+
33
+ html << "<script async
34
+ src=\"https://telegram.org/js/telegram-widget.js?4\"
35
+ data-telegram-login=\"#{options.bot_name}\"
36
+ data-auth-url=\"#{callback_url}\"
37
+ #{data_attrs}></script>"
38
+
39
+ html << <<-HTML
40
+ </body>
41
+ </html>
42
+ HTML
43
+
44
+ Rack::Response.new(html, 200, 'content-type' => 'text/html').finish
45
+ end
46
+
47
+ def callback_phase
48
+ unless FIELDS.all? { |f| request.params.include?(f) }
49
+ fail!(:field_missing)
50
+ end
51
+
52
+ unless check_signature
53
+ fail!(:signature_mismatch)
54
+ end
55
+
56
+ if Time.now.to_i - request.params["auth_date"].to_i > 86400
57
+ fail!(:session_expired)
58
+ end
59
+
60
+ super
61
+ end
62
+
63
+ uid do
64
+ request.params["id"]
65
+ end
66
+
67
+ info do
68
+ {
69
+ name: "#{request.params["first_name"]} #{request.params["last_name"]}",
70
+ nickname: request.params["username"],
71
+ first_name: request.params["first_name"],
72
+ last_name: request.params["last_name"],
73
+ image: request.params["photo_url"]
74
+ }
75
+ end
76
+
77
+ extra do
78
+ {
79
+ auth_date: Time.at(request.params["auth_date"].to_i)
80
+ }
81
+ end
82
+
83
+ private
84
+
85
+ def check_signature
86
+ secret = OpenSSL::Digest::SHA256.digest(options[:bot_secret])
87
+ signature = HASH_FIELDS.map { |f| "%s=%s" % [f, request.params[f]] }.join("\n")
88
+ hashed_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, secret, signature)
89
+
90
+ request.params["hash"] == hashed_signature
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth/telegram/version"
2
+ require "omniauth/strategies/telegram"
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Telegram
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "omniauth/telegram/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "omniauth-telegram"
7
+ spec.version = Omniauth::Telegram::VERSION
8
+ spec.authors = ["Yuri Mikhaylov"]
9
+ spec.email = ["me@yurijmi.ru"]
10
+
11
+ spec.summary = %q{An OmniAuth strategy for Telegram}
12
+ spec.description = %q{An OmniAuth strategy for Telegram}
13
+ spec.homepage = "https://github.com/yurijmi/omniauth-telegram"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "omniauth", "~> 1.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-telegram
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuri Mikhaylov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: An OmniAuth strategy for Telegram
70
+ email:
71
+ - me@yurijmi.ru
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/omniauth/strategies/telegram.rb
86
+ - lib/omniauth/telegram.rb
87
+ - lib/omniauth/telegram/version.rb
88
+ - omniauth-telegram.gemspec
89
+ homepage: https://github.com/yurijmi/omniauth-telegram
90
+ licenses: []
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.7.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: An OmniAuth strategy for Telegram
112
+ test_files: []