Repository navigation
Authentication for Ruby #1760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Authentication for Ruby #1760
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
0c7987c
Implemented allowedhostsvalidator class and made a couple changes to …
osose-e bb94297
Small fix to line 23
osose-e c0438bc
Final commit for this branch
osose-e f5d6d70
Merge pull request #1675 from microsoft/osose-authentication-hostVali…
osose-e 1396654
auth commit 😝
osose-e 6bb6fdb
update
osose-e 505e91d
update
osose-e e2897a0
update
osose-e 2af72e7
update
osose-e d05cb94
update
osose-e e09a543
update
osose-e 9351288
update
osose-e 9c5de63
update
osose-e 40e1dcf
update
osose-e bcbdbdf
update
osose-e 7ff4bd5
update to gemfile
osose-e d49ce3a
update
osose-e 0a44ebf
Gemfile update.
osose-e 037d8bb
update
osose-e b4926e9
update
osose-e 1013b4e
update
osose-e de461ea
Merge pull request #1757 from microsoft/osose-authentication-atpinter…
osose-e 1861486
update
osose-e efacd31
Updated Changelog to Reflect Ruby Auth Additions
osose-e bd05c9f
Commiting some of the changes requested by Philip
osose-e 82e57fd
Merge branch 'osose-e/abstractions/update' of https://github.com/micr…
osose-e 01702f9
Refactoring and Reorganization of Authentication
osose-e 018af3e
Changed access token provider constructor
osose-e 987031f
Fixing the require statements in access token p
osose-e bcb4467
Deleting outdated tests
osose-e f3f67d1
Changes/update to Access Token Provider Interface
osose-e 324a717
Updating changelog, gemspec, and readme
osose-e 58efd21
Removing include statement
osose-e 2fbab0a
Update abstractions/ruby/microsoft_kiota_abstractions/README.md
osose-e 8393769
Updating Custom Context
osose-e 8336b4a
Merge branches 'osose-authentication-features' and 'osose-authenticat…
osose-e 30cbf33
Merge branch 'main' into osose-authentication-features
osose-e ef19054
Update abstractions/ruby/microsoft_kiota_abstractions/lib/microsoft_k…
osose-e 10e6028
Implementing some requested changes
osose-e aa6c24d
Updates to tests to reflect valid host hash
osose-e 87ef5a2
Merge branch 'main' into osose-authentication-features
osose-e a756b0c
Changing Package Name
osose-e 130339d
Merge branch 'osose-authentication-features' of https://github.com/mi…
osose-e f84f076
- adds a workflow for ruby authentication package
baywet 9a0fa4a
- fixes link to badge for ruby authentication package
baywet e05ae21
Update authentication-ruby-oauth.yml
osose-e 4e8b00b
Deleting the Azure Folder
osose-e 264b88a
Merge branch 'osose-authentication-features' of https://github.com/mi…
osose-e 326c302
Adding Auth folder with the name oauth
osose-e 9a6e8ea
Update authentication/ruby/oauth/microsoft_kiota_authentication_oauth…
osose-e c4358a8
Updating scopes on authcode flow
osose-e b2d1137
Updating oauth access token provider
osose-e 2c0e683
Merge branch 'osose-authentication-features' of https://github.com/mi…
osose-e 02b70d2
Updating contexts
osose-e 5351f29
Update to mimic interfaces in custom oauth flow
osose-e 6529b03
Merge branch 'main' into osose-authentication-features
osose-e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| name: Ruby serialization | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: [ main ] | ||
| paths: ['authentication/ruby/**', '.github/workflows/**'] | ||
| pull_request: | ||
| paths: ['authentication/ruby/**', '.github/workflows/**'] | ||
|
|
||
| jobs: | ||
| build: | ||
| env: | ||
| relativePath: ./authentication/ruby/oauth/microsoft_kiota_authentication_oauth | ||
| BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}" | ||
| BUNDLE_RUBYGEMS__PKG__GITHUB__COM: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}" #needed for jruby-head | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-latest, macos-latest] | ||
| # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' | ||
| ruby-version: [2.5, 2.6, 2.7, '3.0', head, jruby, jruby-head, truffleruby, truffleruby-head] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: ruby/setup-ruby@v1 | ||
| with: | ||
| ruby-version: ${{ matrix.ruby-version }} | ||
| bundler-cache: true # runs 'bundle install' and caches installed gems automatically | ||
| bundler: 'latest' | ||
| cache-version: 1 | ||
| working-directory: ${{ env.relativePath }} | ||
| - name: Run tests | ||
| run: bundle exec rake | ||
| working-directory: ${{ env.relativePath }} | ||
| - name: Upload artifacts for ruby version 3 and ubuntu | ||
| if: ${{ matrix.os == 'ubuntu-latest' && matrix.ruby-version == '3.0'}} | ||
| uses: actions/upload-artifact@v3 | ||
| with: | ||
| name: drop | ||
| path: | | ||
| ${{ env.relativePath }}/Gemfile.lock | ||
| ${{ env.relativePath }}/README.md | ||
| deploy: | ||
| if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | ||
| environment: | ||
| name: staging_feeds | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| relativePath: ./authentication/ruby/oauth/microsoft_kiota_authentication_oauth | ||
| BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}" | ||
| needs: [build] | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: ruby/setup-ruby@v1 | ||
| with: | ||
| # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' | ||
| ruby-version: '3.0' | ||
| bundler-cache: true # runs 'bundle install' and caches installed gems automatically | ||
| bundler: 'latest' | ||
| cache-version: 1 | ||
| working-directory: ${{ env.relativePath }} | ||
| - run: bundle exec rake | ||
| working-directory: ${{ env.relativePath }} | ||
| - name: Publish to GPR | ||
| run: | | ||
| mkdir -p $HOME/.gem | ||
| touch $HOME/.gem/credentials | ||
| chmod 0600 $HOME/.gem/credentials | ||
| printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials | ||
| gem build *.gemspec | ||
| gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem | ||
| working-directory: ${{ env.relativePath }} | ||
| env: | ||
| GEM_HOST_API_KEY: "Bearer ${{secrets.PUBLISH_GH_TOKEN}}" | ||
| OWNER: ${{ github.repository_owner }} | ||
| # deploy_prod: | ||
| # if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | ||
| # environment: | ||
| # name: production_feeds | ||
| # runs-on: ubuntu-latest | ||
| # env: | ||
| # relativePath: ./authentication/ruby/oauth/microsoft_kiota_authentication_oauth | ||
| # BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}" | ||
| # needs: [build] | ||
| # steps: | ||
| # - uses: actions/checkout@v3 | ||
| # - uses: ruby/setup-ruby@v1 | ||
| # with: | ||
| # # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' | ||
| # ruby-version: '3.0' | ||
| # bundler-cache: true # runs 'bundle install' and caches installed gems automatically | ||
| # - run: bundle exec rake | ||
| # - name: Publish to RubyGems | ||
| # run: | | ||
| # mkdir -p $HOME/.gem | ||
| # touch $HOME/.gem/credentials | ||
| # chmod 0600 $HOME/.gem/credentials | ||
| # printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials | ||
| # gem build *.gemspec | ||
| # gem push *.gem | ||
| # env: | ||
| # GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" TODO: Token for rubyGems.org | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ota_abstractions/lib/microsoft_kiota_abstractions/authentication/access_token_provider.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'concurrent' | ||
| require_relative 'allowed_hosts_validator' | ||
|
|
||
| module MicrosoftKiotaAbstractions | ||
| # Access Token Provider Module implementation | ||
| module AccessTokenProvider | ||
| # This function obtains the authorization token. | ||
| # :params | ||
| # uri: a string containing the uri | ||
| # additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' } | ||
| # default is empty hash | ||
| def get_authorization_token(uri, additional_properties = {}) | ||
| raise NotImplementedError.new | ||
| end | ||
|
|
||
| attr_accessor :scopes, :host_validator | ||
|
|
||
| end | ||
| end |
37 changes: 37 additions & 0 deletions
37
...a_abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'uri' | ||
|
|
||
| module MicrosoftKiotaAbstractions | ||
| # Maintains a list of valid hosts and allows authentication providers to check whether | ||
| # a host is valid before authenticating a request | ||
| class AllowedHostsValidator | ||
| # creates a new AllocatedHostsValidator with provided values | ||
| def initialize(allowed_hosts) | ||
| @allowed_hosts = {} | ||
| allowed_hosts.each { |host| @allowed_hosts[host.downcase] = true } | ||
| end | ||
|
|
||
| # sets the list of valid hosts with provided value (val) | ||
| def allowed_hosts=(val) | ||
| @allowed_hosts = {} | ||
| val.each { |host| @allowed_hosts[host.downcase] = true } | ||
| end | ||
|
|
||
| # checks whether the provided host is valid | ||
| def url_host_valid?(url) | ||
| return false unless url =~ URI::DEFAULT_PARSER.regexp[:ABS_URI] | ||
|
|
||
| return true if @allowed_hosts.empty? | ||
|
|
||
| parsed_url = URI(url) | ||
|
|
||
| return false if parsed_url.host.nil? | ||
|
|
||
| @allowed_hosts.key? parsed_url.host.downcase | ||
| end | ||
|
|
||
| # gets the list of valid hosts | ||
| attr_reader :allowed_hosts | ||
| end | ||
| end |
6 changes: 2 additions & 4 deletions
6
...a_abstractions/lib/microsoft_kiota_abstractions/authentication/authentication_provider.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,7 @@ | ||
| module MicrosoftKiotaAbstractions | ||
| module AuthenticationProvider | ||
|
|
||
| def authenticate_request(request) | ||
| def authenticate_request(request, additional_properties = {}) | ||
| raise NotImplementedError.new | ||
| end | ||
|
|
||
| end | ||
| end | ||
| end |
34 changes: 18 additions & 16 deletions
34
.../microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,29 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'concurrent' | ||
| require_relative './authentication_provider' | ||
| require_relative './access_token_provider' | ||
|
|
||
| module MicrosoftKiotaAbstractions | ||
| class BaseBearerTokenAuthenticationProvider | ||
| # Provides a base class for implementing AuthenticationProvider for Bearer token scheme | ||
| class BaseBearerTokenAuthenticationProvider | ||
| include MicrosoftKiotaAbstractions::AccessTokenProvider | ||
| include MicrosoftKiotaAbstractions::AuthenticationProvider | ||
| include Concurrent::Async | ||
| def initialize(access_token_provider) | ||
| raise StandardError, 'access_token_provider parameter cannot be nil' if access_token_provider.nil? | ||
|
|
||
| @access_token_provider = access_token_provider | ||
| end | ||
|
|
||
| AUTHORIZATION_HEADER_KEY = 'Authorization' | ||
| def authenticate_request(request) | ||
| if !request | ||
| raise StandardError, 'request cannot be null' | ||
| end | ||
| if !request.headers.has_key?(AUTHORIZATION_HEADER_KEY) | ||
| token = self.get_authorization_token(request) | ||
| if !token | ||
| raise StandardError, 'Could not get an authorization token' | ||
| end | ||
| request.headers[AUTHORIZATION_HEADER_KEY] = 'Bearer ' + token | ||
| end | ||
| end | ||
| def authenticate_request(request, additional_properties) | ||
| raise StandardError, 'Request cannot be null' if request.nil? | ||
| return if request.headers.key?(AUTHORIZATION_HEADER_KEY) | ||
|
|
||
| token = @access_token_provider.get_authorization_token(request, additional_properties) | ||
|
|
||
| def get_authorization_token(request) | ||
| raise NotImplementedError, 'get_authorization_token must be implemented' | ||
| request.headers[AUTHORIZATION_HEADER_KEY] = "Bearer #{token}" unless token.nil? | ||
| end | ||
| end | ||
| end | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
authentication/ruby/oauth/microsoft_kiota_authentication_oauth/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /.bundle/ | ||
| /.yardoc | ||
| /_yardoc/ | ||
| /coverage/ | ||
| /doc/ | ||
| /pkg/ | ||
| /spec/reports/ | ||
| /tmp/ | ||
|
|
||
| # rspec failure tracking | ||
| .rspec_status |
24 changes: 24 additions & 0 deletions
24
authentication/ruby/oauth/microsoft_kiota_authentication_oauth/Gemfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| source 'https://rubygems.org' | ||
|
|
||
| # Specify your gem's dependencies in microsoft_kiota_authentication.gemspec | ||
| gemspec | ||
|
|
||
| # git_source(:github) { |repo_name| "https://rubygems.pkg.github.com/microsoft" } | ||
|
|
||
| source "https://rubygems.pkg.github.com/microsoft" do | ||
| gem "microsoft_kiota_abstractions", "0.2.0" | ||
| end | ||
|
|
||
| gem 'rake', '~> 13.0' | ||
|
|
||
| gem 'rspec', '~> 3.0' | ||
|
|
||
| gem 'rubocop', require: false | ||
|
|
||
| gem 'concurrent-ruby', '~> 1.1', '>= 1.1.9' | ||
|
|
||
| gem 'addressable', '~> 2.7', '>= 2.7.0' | ||
|
|
||
| gem "oauth2", "~> 2.0" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.