Skip to content
Merged
Show file tree
Hide file tree
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 Jun 29, 2022
bb94297
Small fix to line 23
osose-e Jun 29, 2022
c0438bc
Final commit for this branch
osose-e Jun 29, 2022
f5d6d70
Merge pull request #1675 from microsoft/osose-authentication-hostVali…
osose-e Jun 29, 2022
1396654
auth commit 😝
osose-e Jul 20, 2022
6bb6fdb
update
osose-e Jul 20, 2022
505e91d
update
osose-e Jul 20, 2022
e2897a0
update
osose-e Jul 20, 2022
2af72e7
update
osose-e Jul 20, 2022
d05cb94
update
osose-e Jul 20, 2022
e09a543
update
osose-e Jul 20, 2022
9351288
update
osose-e Jul 20, 2022
9c5de63
update
osose-e Jul 20, 2022
40e1dcf
update
osose-e Jul 20, 2022
bcbdbdf
update
osose-e Jul 20, 2022
7ff4bd5
update to gemfile
osose-e Jul 21, 2022
d49ce3a
update
osose-e Jul 21, 2022
0a44ebf
Gemfile update.
osose-e Jul 21, 2022
037d8bb
update
osose-e Jul 21, 2022
b4926e9
update
osose-e Jul 21, 2022
1013b4e
update
osose-e Jul 21, 2022
de461ea
Merge pull request #1757 from microsoft/osose-authentication-atpinter…
osose-e Jul 21, 2022
1861486
update
osose-e Jul 21, 2022
efacd31
Updated Changelog to Reflect Ruby Auth Additions
osose-e Jul 25, 2022
bd05c9f
Commiting some of the changes requested by Philip
osose-e Jul 26, 2022
82e57fd
Merge branch 'osose-e/abstractions/update' of https://github.com/micr…
osose-e Aug 12, 2022
01702f9
Refactoring and Reorganization of Authentication
osose-e Aug 15, 2022
018af3e
Changed access token provider constructor
osose-e Aug 15, 2022
987031f
Fixing the require statements in access token p
osose-e Aug 15, 2022
bcb4467
Deleting outdated tests
osose-e Aug 15, 2022
f3f67d1
Changes/update to Access Token Provider Interface
osose-e Aug 15, 2022
324a717
Updating changelog, gemspec, and readme
osose-e Aug 15, 2022
58efd21
Removing include statement
osose-e Aug 15, 2022
2fbab0a
Update abstractions/ruby/microsoft_kiota_abstractions/README.md
osose-e Aug 15, 2022
8393769
Updating Custom Context
osose-e Aug 15, 2022
8336b4a
Merge branches 'osose-authentication-features' and 'osose-authenticat…
osose-e Aug 15, 2022
30cbf33
Merge branch 'main' into osose-authentication-features
osose-e Aug 15, 2022
ef19054
Update abstractions/ruby/microsoft_kiota_abstractions/lib/microsoft_k…
osose-e Aug 16, 2022
10e6028
Implementing some requested changes
osose-e Aug 16, 2022
aa6c24d
Updates to tests to reflect valid host hash
osose-e Aug 16, 2022
87ef5a2
Merge branch 'main' into osose-authentication-features
osose-e Aug 16, 2022
a756b0c
Changing Package Name
osose-e Aug 16, 2022
130339d
Merge branch 'osose-authentication-features' of https://github.com/mi…
osose-e Aug 16, 2022
f84f076
- adds a workflow for ruby authentication package
baywet Aug 17, 2022
9a0fa4a
- fixes link to badge for ruby authentication package
baywet Aug 17, 2022
e05ae21
Update authentication-ruby-oauth.yml
osose-e Aug 17, 2022
4e8b00b
Deleting the Azure Folder
osose-e Aug 17, 2022
264b88a
Merge branch 'osose-authentication-features' of https://github.com/mi…
osose-e Aug 17, 2022
326c302
Adding Auth folder with the name oauth
osose-e Aug 17, 2022
9a6e8ea
Update authentication/ruby/oauth/microsoft_kiota_authentication_oauth…
osose-e Aug 17, 2022
c4358a8
Updating scopes on authcode flow
osose-e Aug 17, 2022
b2d1137
Updating oauth access token provider
osose-e Aug 17, 2022
2c0e683
Merge branch 'osose-authentication-features' of https://github.com/mi…
osose-e Aug 17, 2022
02b70d2
Updating contexts
osose-e Aug 17, 2022
5351f29
Update to mimic interfaces in custom oauth flow
osose-e Aug 18, 2022
6529b03
Merge branch 'main' into osose-authentication-features
osose-e Aug 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/authentication-ruby-oauth.yml
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

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adds python code generation support. [#1200](https://github.com/microsoft/kiota/issues/163)
- Added native type support for Duration, Time Only, and Date Only in Ruby. [#1644](https://github.com/microsoft/kiota/issues/1644)
- Added a `--additional-data` argument to generate the AdditionalData properties [#1772](https://github.com/microsoft/kiota/issues/1772)
- Added CAE infrastructure in Ruby by adding an `--additional-properties` parameter to the authenticate method of AuthenticationProvider, the get access token method of the AccessTokenProvider in Ruby. [#1643](https://github.com/microsoft/kiota/issues/1643)
- Added Kiota authentication library for Ruby. [#421](https://github.com/microsoft/kiota/issues/421)

### Changed

Expand All @@ -32,8 +34,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed an issue where duplicate 'require' statements are generated for inner classes in the middle of the file (Ruby). [#1649](https://github.com/microsoft/kiota/issues/1649)
- Split parsable interface and additional property/data interface in Ruby. [#1654](https://github.com/microsoft/kiota/issues/1654)
- Changed format of datetimes in Go to be converted to ISO 8601 by default when place in path parameters(Go)
- Defined the Access Token Provider Interface for Ruby authentication. [#1638](https://github.com/microsoft/kiota/issues/1638)
- Reduce code verbosity on Go Getters and Setters. [G0#26][https://github.com/microsoftgraph/msgraph-sdk-go-core/issues/26]


## [0.3.0] - 2022-07-08

### Added
Expand All @@ -46,6 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for vendor specific content types(PHP) [#1464](https://github.com/microsoft/kiota/issues/1464)
- Added support for accept request header (PHP) [#1616](https://github.com/microsoft/kiota/issues/1616)
- Added Getting Started steps for PHP. [#1642](https://github.com/microsoft/kiota/pull/1642)
- Defined the Access Token Provider interface (Ruby) [#1638](https://github.com/microsoft/kiota/issues/1638)
- Added Continuous Access Evalution infrastructure (Ruby) [#1643](https://github.com/microsoft/kiota/issues/1643)

### Changed

Expand Down
3 changes: 0 additions & 3 deletions abstractions/ruby/microsoft_kiota_abstractions/.rspec

This file was deleted.

2 changes: 1 addition & 1 deletion abstractions/ruby/microsoft_kiota_abstractions/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ gem 'concurrent-ruby', '~> 1.1', '>= 1.1.9'

gem 'addressable', '~> 2.7', '>= 2.7.0'

gem 'iso8601', '~> 0.13.0'
gem 'iso8601', '~> 0.13.0'
2 changes: 1 addition & 1 deletion abstractions/ruby/microsoft_kiota_abstractions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bundle install
Or install it yourself as:

```shell
gem install microsoft_kiota_abstractions --version "0.1.11" --source "https://{USERNAME}{PASSWORD/TOKEN}rubygems.pkg.github.com/microsoft"
gem install microsoft_kiota_abstractions --version "0.2.0" --source "https://{USERNAME}{PASSWORD/TOKEN}rubygems.pkg.github.com/microsoft"
```

## Contributing
Expand Down
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
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
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
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
Comment thread
osose-e marked this conversation as resolved.
Resolved
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

Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
expect(token_provider).not_to be nil
end

it "creates a bearer token provider" do
token_provider = MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider.new()
expect(token_provider).not_to be nil
end

it "throws if the token method is not implemented" do
token_provider = MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider.new()
expect { token_provider.authenticate_request(MicrosoftKiotaAbstractions::RequestInformation.new()) }.to raise_error(NotImplementedError)
end

it "returns the raw URI when set via setter" do
request_obj = MicrosoftKiotaAbstractions::RequestInformation.new
request_obj.path_parameters["term"] = "search"
Expand Down Expand Up @@ -91,4 +81,39 @@
time2 = MicrosoftKiotaAbstractions::ISODuration.new({ :years => 4, :months => 2, :hours => 2 } )
expect(time1).to eq(time2)
end

it 'initializes empty allowed hosts properly' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new([])
expect(ahv.allowed_hosts).to eq({})
end

it 'initializes non-empty/cased allowed hosts properly' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['microsoft.com', 'Graph.microsoft.com', 'DOD-graph.microsoft.us'])
valid_hosts = ahv.allowed_hosts
expect(valid_hosts).to eq({'microsoft.com' => true, 'graph.microsoft.com' => true, 'dod-graph.microsoft.us' => true})
end

it 'tests the setter for allowed hosts on allowed hosts validator' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['microsoft.com', 'Graph.microsoft.com', 'DOD-graph.microsoft.us'])
ahv.allowed_hosts = ['MICROSOFT.com', 'GRAPH.microsoft.COM', 'DOD-graph.microsoft.us', 'graph.microsoft.de']
expect(ahv.allowed_hosts).to eq({'microsoft.com' => true, 'graph.microsoft.com' => true, 'dod-graph.microsoft.us' => true, 'graph.microsoft.de' => true})
end

it 'tests url_host_valid? method on malformed and valid urls' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['www.google.com', 'example.com', 'Graph.microsoft.com',
'DOD-graph.microsoft.us', "cool/groovy/art"])
url1 = ahv.url_host_valid?("https://www.google.com")
url2 = ahv.url_host_valid?("htts://google.com")
url3 = ahv.url_host_valid?("cool/groovy/art")
url4 = ahv.url_host_valid?("http://example.com")
url5 = ahv.url_host_valid?('https%3A%2F%2Fwww.example.com')
url6 = ahv.url_host_valid?('%3A%2F%2F')
expect(url1).to eq(true)
expect(url2).to eq(false)
expect(url3).to eq(false)
expect(url4).to eq(true)
expect(url5).to eq(false)
expect(url5).to eq(false)
expect(url6).to eq(false)
end
end
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
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"
Loading