omniauth-lokalise 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bf2769aac9e539398210793f0fa1f99006f6bce913239e5d4d582b75a1fd1dc8
4
+ data.tar.gz: 66d92bb92143c7c26c986828079558b8b17b2e4a5458e236828fe9d32fbc77ef
5
+ SHA512:
6
+ metadata.gz: 843cec4e69000ed694034ebd05b4ba0d4577acb9491495090e57fb9d797b07996cea6b9bc31ef549ecc36ccb1dedef69dd6326d75d9b6889782d8053ba0d3c26
7
+ data.tar.gz: 8eb255425d01adab6ce5c1d87381a14d50bb424197e7f4197d00764627ae75112e0054821c1ed182b693b3d9ba73efbb2b4197827ca91d1be5cecf5ced0b06f5
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hello@lokalise.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,21 @@
1
+ # Contributing
2
+
3
+ 1. [Fork the repository.][fork]
4
+ 2. [Create a topic branch.][branch]
5
+ 3. Implement your feature or bug fix.
6
+ 4. Don't forget to add specs and make sure they pass by running `rspec .`.
7
+ 5. Make sure your code complies with the style guide by running `rubocop`. `rubocop -a` can automatically fix most issues for you. Run `rubocop -A` to make it more aggressive.
8
+ 6. If necessary, add documentation for your feature or bug fix.
9
+ 7. Commit and push your changes.
10
+ 8. [Submit a pull request.][pr]
11
+
12
+ [fork]: http://help.github.com/fork-a-repo/
13
+ [branch]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-branches
14
+ [pr]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests
15
+
16
+ ## Previewing the docs locally
17
+
18
+ 1. Clone the repo.
19
+ 2. `cd docs`
20
+ 3. `bundle exec jekyll serve --baseurl=''`.
21
+ 4. Navigate to `http://localhost:4000` and observe the docs.
@@ -0,0 +1,11 @@
1
+ ### Summary
2
+
3
+ Provide a general description of the code changes in your pull
4
+ request. Were there any bugs you had fixed? If so, mention them. If
5
+ these bugs have open GitHub issues, be sure to tag them here as well,
6
+ to keep the conversation linked together.
7
+
8
+ ### Other Information
9
+
10
+ If there's anything else that's important and relevant to your pull
11
+ request, mention that information here.
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.0.1 (28-Apr-22)
4
+
5
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Ilya Krukowski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Omniauth Lokalise
2
+
3
+ This is an official OmniAuth strategy for [https://lokalise.com](Lokalise).
4
+
5
+ ## Prerequisites
6
+
7
+ As the first step, you have to register a new OAuth 2 app at Lokalise by contacting the support team and providing the following info:
8
+
9
+ * Title of your application
10
+ * Logo of your application (150x150px, PNG or JPG)
11
+ * Description of your application (optional)
12
+ * Link to app website/documentation (optional)
13
+ * Required scopes. Find the list required scopes for the corresponding API endpoints in the [Lokalise API docs](https://app.lokalise.com/api2docs/curl/). Please note that your can further adjust these scopes as needed when setting up Omniauth.
14
+
15
+ After registering, you'll obtain a client ID and client secret. **Do not publicly expose your client secret!**
16
+
17
+ [*Find detailed information in the Lokalise docs.*](https://docs.lokalise.com/en/articles/5574713-oauth-2)
18
+
19
+ ## Installation
20
+
21
+ Add a new gem to your `Gemfile`:
22
+
23
+ ```ruby
24
+ gem 'omniauth-lokalise'
25
+ ```
26
+
27
+ Run:
28
+
29
+ ```
30
+ bundle install
31
+ ```
32
+
33
+ ## Configuration
34
+
35
+ Create a new `config/initializers/omniauth.rb` file with the following contents:
36
+
37
+ ```ruby
38
+ Rails.application.config.middleware.use OmniAuth::Builder do
39
+ provider :lokalise, 'OAUTH2_CLIENT_ID', 'OAUTH2_CLIENT_SECRET',
40
+ scope: 'required_scopes'
41
+ end
42
+ ```
43
+
44
+ Paste your client ID, client secret and a list of scopes separated with spaces, for example: `'read_projects write_files'`.
45
+
46
+ ## Usage
47
+
48
+ Add a login button somewhere in your views (disable Turbo if you use it in your app):
49
+
50
+ ```html
51
+ <%= form_tag('/auth/lokalise', method: 'post', data: {turbo: false}) do %>
52
+ <button type='submit'>Login with Lokalise</button>
53
+ <% end %>
54
+ ```
55
+
56
+ Create a callback route:
57
+
58
+ ```ruby
59
+ get '/auth/:provider/callback', to: 'sessions#create'
60
+ ```
61
+
62
+ Use `request.env['omniauth.auth']` to fetch OAuth 2 access token and refresh token:
63
+
64
+ ```ruby
65
+ token = request.env['omniauth.auth']['credentials']['token']
66
+ refresh_token = request.env['omniauth.auth']['credentials']['refresh_token']
67
+ ```
68
+
69
+ Please note that currently Lokalise does not provide any information about the logged in user except for credentials. In other words, you can't get access to the user name, uid, email, etc.
70
+
71
+ ## Using refresh token
72
+
73
+ Access tokens usually expire in 60 minutes but you can request a new one using refresh token. To achieve that, utilize [ruby-lokalise-api](https://github.com/lokalise/ruby-lokalise-api) client:
74
+
75
+ ```ruby
76
+ require 'ruby_lokalise_api'
77
+
78
+ auth_client = RubyLokaliseApi.auth_client 'OAUTH2_CLIENT_ID', 'OAUTH2_CLIENT_SECRET'
79
+ response = auth_client.refresh 'YOUR_REFRESH_TOKEN'
80
+ token = response['access_token']
81
+ ```
82
+
83
+ ## License
84
+
85
+ This gem is licensed under the [MIT license](./LICENSE).
86
+
87
+ (c) 2022 Ilya Krukowski
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |task|
7
+ task.libs << 'test'
8
+ task.test_files = FileList['test/*_test.rb']
9
+ end
10
+
11
+ task default: :test
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Lokalise
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/lokalise/version'
4
+ require 'omniauth/strategies/lokalise'
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Lokalise < OmniAuth::Strategies::OAuth2
8
+ option :name, 'lokalise'
9
+
10
+ option :client_options, {
11
+ site: 'https://app.lokalise.com',
12
+ authorize_url: 'oauth2/auth',
13
+ token_url: 'oauth2/token',
14
+ grant_type: 'authorization_code'
15
+ }
16
+
17
+ uid { nil }
18
+
19
+ info do
20
+ {
21
+ # :name => raw_info['name'],
22
+ # :email => raw_info['email']
23
+ }
24
+ end
25
+
26
+ extra do
27
+ {
28
+ 'raw_info' => raw_info
29
+ }
30
+ end
31
+
32
+ def raw_info
33
+ # @raw_info ||= access_token.get('/me').parsed
34
+ {}
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/lokalise'
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe OmniAuth::Strategies::Lokalise do
6
+ let(:access_token) { instance_double('AccessToken', :options => {}, :[] => 'user') }
7
+
8
+ let(:strat) do
9
+ described_class.new({})
10
+ end
11
+
12
+ before do
13
+ allow(strat).to receive(:access_token).and_return(access_token)
14
+ end
15
+
16
+ context 'client options' do
17
+ it 'has correct site' do
18
+ expect(strat.options.client_options.site).to eq('https://app.lokalise.com')
19
+ end
20
+
21
+ it 'has correct authorize_url' do
22
+ expect(strat.options.client_options.authorize_url).to eq('oauth2/auth')
23
+ end
24
+
25
+ it 'has correct token_url' do
26
+ expect(strat.options.client_options.token_url).to eq('oauth2/token')
27
+ end
28
+
29
+ it 'has correct grant_type' do
30
+ expect(strat.options.client_options.grant_type).to eq('authorization_code')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path(__dir__)
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
5
+
6
+ require 'rspec'
7
+
8
+ require 'omniauth'
9
+ require 'omniauth-lokalise'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-lokalise
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ilya Krukowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-28 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: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.1
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.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ description: Official Omniauth (OAuth 2) strategy for Lokalise TMS
70
+ email:
71
+ - golosizpru@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - README.md
76
+ files:
77
+ - ".github/CODE_OF_CONDUCT.md"
78
+ - ".github/CONTRIBUTING.md"
79
+ - ".github/PULL_REQUEST_TEMPLATE.md"
80
+ - CHANGELOG.md
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - lib/omniauth-lokalise.rb
86
+ - lib/omniauth/lokalise.rb
87
+ - lib/omniauth/lokalise/version.rb
88
+ - lib/omniauth/strategies/lokalise.rb
89
+ - spec/omniauth/strategies/lokalise_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/bodrovis/omniauth-lokalise
92
+ licenses:
93
+ - MIT
94
+ metadata:
95
+ rubygems_mfa_required: 'true'
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '2.5'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.3.11
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Omniauth strategy for Lokalise
115
+ test_files:
116
+ - spec/omniauth/strategies/lokalise_spec.rb
117
+ - spec/spec_helper.rb