omniauth-azure-activedirectory-davevanfleet 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rubocop.yml +8 -0
  4. data/.rubocop_todo.yml +20 -0
  5. data/.travis.yml +7 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +86 -0
  9. data/RELEASES.md +48 -0
  10. data/Rakefile +22 -0
  11. data/examples/rails-todo-list-app/.gitignore +25 -0
  12. data/examples/rails-todo-list-app/Gemfile +33 -0
  13. data/examples/rails-todo-list-app/README.md +83 -0
  14. data/examples/rails-todo-list-app/Rakefile +3 -0
  15. data/examples/rails-todo-list-app/app/assets/javascripts/application.js +4 -0
  16. data/examples/rails-todo-list-app/app/assets/stylesheets/application.css +2 -0
  17. data/examples/rails-todo-list-app/app/controllers/application_controller.rb +3 -0
  18. data/examples/rails-todo-list-app/app/controllers/home_controller.rb +2 -0
  19. data/examples/rails-todo-list-app/app/controllers/profile_controller.rb +20 -0
  20. data/examples/rails-todo-list-app/app/controllers/sessions_controller.rb +28 -0
  21. data/examples/rails-todo-list-app/app/controllers/signed_in_controller.rb +25 -0
  22. data/examples/rails-todo-list-app/app/controllers/tasks_controller.rb +33 -0
  23. data/examples/rails-todo-list-app/app/models/task.rb +10 -0
  24. data/examples/rails-todo-list-app/app/models/user.rb +58 -0
  25. data/examples/rails-todo-list-app/app/views/home/index.html.haml +4 -0
  26. data/examples/rails-todo-list-app/app/views/layouts/application.html.haml +12 -0
  27. data/examples/rails-todo-list-app/app/views/layouts/signed_in.html.haml +18 -0
  28. data/examples/rails-todo-list-app/app/views/profile/index.html.haml +13 -0
  29. data/examples/rails-todo-list-app/app/views/tasks/index.html.haml +11 -0
  30. data/examples/rails-todo-list-app/bin/bundle +3 -0
  31. data/examples/rails-todo-list-app/bin/rails +4 -0
  32. data/examples/rails-todo-list-app/bin/rake +4 -0
  33. data/examples/rails-todo-list-app/bin/setup +29 -0
  34. data/examples/rails-todo-list-app/config.ru +4 -0
  35. data/examples/rails-todo-list-app/config/application.rb +29 -0
  36. data/examples/rails-todo-list-app/config/boot.rb +3 -0
  37. data/examples/rails-todo-list-app/config/database.yml +25 -0
  38. data/examples/rails-todo-list-app/config/environment.rb +13 -0
  39. data/examples/rails-todo-list-app/config/environments/development.rb +41 -0
  40. data/examples/rails-todo-list-app/config/environments/production.rb +79 -0
  41. data/examples/rails-todo-list-app/config/environments/test.rb +42 -0
  42. data/examples/rails-todo-list-app/config/initializers/assets.rb +11 -0
  43. data/examples/rails-todo-list-app/config/initializers/backtrace_silencers.rb +7 -0
  44. data/examples/rails-todo-list-app/config/initializers/cookies_serializer.rb +3 -0
  45. data/examples/rails-todo-list-app/config/initializers/filter_parameter_logging.rb +4 -0
  46. data/examples/rails-todo-list-app/config/initializers/inflections.rb +16 -0
  47. data/examples/rails-todo-list-app/config/initializers/mime_types.rb +4 -0
  48. data/examples/rails-todo-list-app/config/initializers/omniauth.rb +3 -0
  49. data/examples/rails-todo-list-app/config/initializers/session_store.rb +3 -0
  50. data/examples/rails-todo-list-app/config/initializers/wrap_parameters.rb +14 -0
  51. data/examples/rails-todo-list-app/config/routes.rb +22 -0
  52. data/examples/rails-todo-list-app/db/schema.rb +35 -0
  53. data/examples/rails-todo-list-app/public/404.html +67 -0
  54. data/examples/rails-todo-list-app/public/422.html +67 -0
  55. data/examples/rails-todo-list-app/public/500.html +66 -0
  56. data/examples/rails-todo-list-app/public/favicon.ico +0 -0
  57. data/examples/sinatra-multiple-providers-app/.env +11 -0
  58. data/examples/sinatra-multiple-providers-app/Gemfile +8 -0
  59. data/examples/sinatra-multiple-providers-app/README.md +13 -0
  60. data/examples/sinatra-multiple-providers-app/app.rb +51 -0
  61. data/examples/sinatra-multiple-providers-app/config.ru +45 -0
  62. data/lib/omniauth-azure-activedirectory-davevanfleet.rb +23 -0
  63. data/lib/omniauth/azure_activedirectory_davevanfleet.rb +24 -0
  64. data/lib/omniauth/azure_activedirectory_davevanfleet/version.rb +28 -0
  65. data/lib/omniauth/strategies/azure_activedirectory_davevanfleet.rb +329 -0
  66. data/omniauth-azure-activedirectory-davevanfleet.gemspec +29 -0
  67. data/spec/fixtures/id_token.txt +1 -0
  68. data/spec/fixtures/id_token_bad_audience.txt +1 -0
  69. data/spec/fixtures/id_token_bad_chash.txt +1 -0
  70. data/spec/fixtures/id_token_bad_issuer.txt +1 -0
  71. data/spec/fixtures/id_token_bad_kid.txt +1 -0
  72. data/spec/fixtures/id_token_bad_nonce.txt +1 -0
  73. data/spec/fixtures/id_token_no_alg.txt +1 -0
  74. data/spec/fixtures/x5c.txt +1 -0
  75. data/spec/fixtures/x5c_different.txt +1 -0
  76. data/spec/omniauth/strategies/azure_activedirectory_davevanfleet_spec.rb +222 -0
  77. data/spec/spec_helper.rb +44 -0
  78. metadata +245 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 828fe19975bac7f5f474aa857ccf270f4179b820d356e867e0a14a967394be11
4
+ data.tar.gz: 378db41b6ec6417c33f76be86cc48096514452e8ca3a45e0cdd596bb41fd85b3
5
+ SHA512:
6
+ metadata.gz: 7c119bf089fdc6d9c8e9723a697415dc1c882680d718aca30c584e4c15543fa8922240d94f5edcf292ddfc082e828c672c5f82c9cd0801a34ecb88e2668170ee
7
+ data.tar.gz: f01ac84858a88f18e70955a649761797e84fb2529e3dafff112ec548bcf61a10e8035cf7ddfce3616d198d41a4ad4acc45038da3352b5d64233f23a9c4674089
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ *.log
3
+ .bundle
4
+ coverage
5
+ .powenv
6
+ .rspec
7
+ Gemfile.lock
8
+ pkg/*
9
+ tmp
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - 'spec/fixtures/**/*'
6
+
7
+ Style/Encoding:
8
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,20 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-08-06 14:09:24 -0700 using RuboCop version 0.32.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 2
9
+ Metrics/AbcSize:
10
+ Max: 19
11
+
12
+ # Offense count: 1
13
+ # Configuration parameters: CountComments.
14
+ Metrics/ClassLength:
15
+ Max: 118
16
+
17
+ # Offense count: 1
18
+ # Configuration parameters: Exclude.
19
+ Style/FileName:
20
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+
7
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Dave Van Fleet
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # OmniAuth Azure Active Directory
2
+
3
+ This is a fork of Microsoft's official ruby gem for Azure Active Directory as an omniauth provider. Most of this README is taken from Microsoft's original gem, [found here](https://github.com/AzureAD/omniauth-azure-activedirectory).
4
+
5
+ OmniAuth strategy to authenticate to Azure Active Directory via OpenId Connect.
6
+
7
+ Before starting, set up a tenant and register a Web Application at [https://manage.windowsazure.com](https://manage.windowsazure.com). Note your client id and tenant for later.
8
+
9
+ # Why this Repo?
10
+
11
+ While Microsoft's original gem still works, when Azure AD is being used as the only provider for omniauth, it hasn't been updated in a significant amount of time. When trying to implement this gem in my own projects, I faced the issue of having many runtime dependency conflicts, meaning I either needed to use older versions of other provider gems (not always possible), or update this gem for myself. This repo is the result of deciding on the latter.
12
+
13
+ ## Samples and Documentation
14
+
15
+ [Find Microsoft's examples here](https://github.com/AzureADSamples) to help you get started with learning the Azure Identity system. This includes tutorials for native clients such as Windows, Windows Phone, iOS, OSX, Android, and Linux. We also provide full walkthroughs for authentication flows such as OAuth2, OpenID Connect, Graph API, and other awesome features.
16
+
17
+ ## How to use this SDK
18
+
19
+ #### Installation
20
+
21
+ Add to your Gemfile:
22
+
23
+ ```ruby
24
+ gem 'omniauth-azure-activedirectory-davevanfleet'
25
+ ```
26
+
27
+ ### Usage
28
+
29
+ If you are already using OmniAuth, adding AzureAD is as simple as adding a new provider to your `OmniAuth::Builder`. The provider requires your AzureAD client id and your AzureAD tenant.
30
+
31
+ For example, in Rails you would add this in `config/initializers/omniauth.rb`:
32
+
33
+ ```ruby
34
+ Rails.application.config.middleware.use OmniAuth::Builder do
35
+ provider :azure_activedirectory_davevanfleet, ENV['AAD_CLIENT_ID'], ENV['AAD_TENANT']
36
+ # other providers here
37
+ end
38
+ ```
39
+
40
+ When you want to authenticate the user, simply redirect them to `/auth/azureactivedirectorydavevanfleet`. From there, OmniAuth will takeover. Once the user authenticates (or fails to authenticate), they will be redirected to `/auth/azureactivedirectorydavevanfleet/callback`. The authentication result is available in `request.env['omniauth.auth']`.
41
+
42
+
43
+ ### Auth Hash
44
+
45
+ OmniAuth AzureAD tries to be consistent with the auth hash schema recommended by OmniAuth. [https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema](https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema).
46
+
47
+ Here's an example of an authentication hash available in the callback. You can access this hash as `request.env['omniauth.auth']`.
48
+
49
+ ```
50
+ :provider => "azureactivedirectory",
51
+ :uid => "123456abcdef",
52
+ :info => {
53
+ :name => "John Smith",
54
+ :email => "jsmith@contoso.net",
55
+ :first_name => "John",
56
+ :last_name => "Smith"
57
+ },
58
+ :credentials => {
59
+ :code => "ffdsjap9fdjw893-rt2wj8r9r32jnkdsflaofdsa9"
60
+ },
61
+ :extra => {
62
+ :session_state => '532fgdsgtfera32',
63
+ :raw_info => {
64
+ :id_token => "fjeri9wqrfe98r23.fdsaf121435rt.f42qfdsaf",
65
+ :id_token_claims => {
66
+ "aud" => "fdsafdsa-fdsafd-fdsa-sfdasfds",
67
+ "iss" => "https://sts.windows.net/fdsafdsa-fdsafdsa/",
68
+ "iat" => 53315113,
69
+ "nbf" => 53143215,
70
+ "exp" => 53425123,
71
+ "ver" => "1.0",
72
+ "tid" => "5ffdsa2f-dsafds-sda-sds",
73
+ "oid" => "fdsafdsaafdsa",
74
+ "upn" => "jsmith@contoso.com",
75
+ "sub" => "123456abcdef",
76
+ "nonce" => "fdsaf342rfdsafdsafsads"
77
+ },
78
+ :id_token_header => {
79
+ "typ" => "JWT",
80
+ "alg" => "RS256",
81
+ "x5t" => "fdsafdsafdsafdsa4t4er32",
82
+ "kid" => "tjiofpjd8ap9fgdsa44"
83
+ }
84
+ }
85
+ }
86
+ ```
data/RELEASES.md ADDED
@@ -0,0 +1,48 @@
1
+ # Microsoft Identity SDK Versioning and Servicing FAQ
2
+
3
+ We have adopted the semantic versioning flow that is industry standard for OSS projects. It gives the maximum amount of control on what risk you take with what versions. If you know how semantic versioning works with node.js, java, and ruby none of this will be new.
4
+
5
+ ##Semantic Versioning and API stability promises
6
+
7
+ Microsoft Identity libraries are independent open source libraries that are used by partners both internal and external to Microsoft. As with the rest of Microsoft, we have moved to a rapid iteration model where bugs are fixed daily and new versions are produced as required. To communicate these frequent changes to external partners and customers, we use semantic versioning for all our public Microsoft Identity SDK libraries. This follows the practices of other open source libraries on the internet. This allows us to support our downstream partners which will lock on certain versions for stability purposes, as well as providing for the distribution over NuGet, CocoaPods, and Maven.
8
+
9
+ The semantics are: MAJOR.MINOR.PATCH (example 1.1.5)
10
+
11
+ We will update our code distributions to use the latest PATCH semantic version number in order to make sure our customers and partners get the latest bug fixes. Downstream partner needs to pull the latest PATCH version. Most partners should try lock on the latest MINOR version number in their builds and accept any updates in the PATCH number.
12
+
13
+ Examples:
14
+ Using Cocapods, the following in the podfile will take the latest ADALiOS build that is > 1.1 but not 1.2.
15
+ ```
16
+ pod 'ADALiOS', '~> 1.1'
17
+ ```
18
+
19
+ Using NuGet, this ensures all 1.1.0 to 1.1.x updates are included when building your code, but not 1.2.
20
+
21
+ ```
22
+ <dependency
23
+ id="ADALfordotNet"
24
+ version="[1.1,1.2)"
25
+ />
26
+ ```
27
+
28
+ | Version | Description | Example |
29
+ |:-------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------:|
30
+ | x.x.x | PATCH version number. Incrementing these numbers is for bug fixes and updates but do not introduce new features. This is used for close partners who build on our platform release (ex. Azure AD Fabric, Office, etc.),In addition, Cocoapods, NuGet, and Maven use this number to deliver the latest release to customers.,This will update frequently (sometimes within the same day),There is no new features, and no regressions or API surface changes. Code will continue to work unless affected by a particular code fix. | ADAL for iOS 1.0.10,(this was a fix for the Storyboard display that was fixed for a specific Office team) |
31
+ | x.x | MINOR version numbers. Incrementing these second numbers are for new feature additions that do not impact existing features or introduce regressions. They are purely additive, but may require testing to ensure nothing is impacted.,All x.x.x bug fixes will also roll up in to this number.,There is no regressions or API surface changes. Code will continue to work unless affected by a particular code fix or needs this new feature. | ADAL for iOS 1.1.0,(this added WPJ capability to ADAL, and rolled all the updates from 1.0.0 to 1.0.12) |
32
+ | x | MAJOR version numbers. This should be considered a new, supported version of Microsoft Identity SDK and begins the Azure two year support cycle anew. Major new features are introduced and API changes can occur.,This should only be used after a large amount of testing and used only if those features are needed.,We will continue to service MAJOR version numbers with bug fixes up to the two year support cycle. | ADAL for iOS 1.0,(our first official release of ADAL) |
33
+
34
+
35
+
36
+ ## Serviceability
37
+
38
+ When we release a new MINOR version, the previous MINOR version is abandoned.
39
+
40
+ When we release a new MAJOR version, we will continue to apply bug fixes to the existing features in the previous MAJOR version for up to the 2 year support cycle for Azure.
41
+ Example: We release ADALiOS 2.0 in the future which supports unified Auth for AAD and MSA. Later, we then have a fix in Conditional Access for ADALiOS. Since that feature exists both in ADALiOS 1.1 and ADALiOS 2.0, we will fix both. It will roll up in a PATCH number for each. Customers that are still locked down on ADALiOS 1.1 will receive the benefit of this fix.
42
+
43
+ ## Microsoft Identity SDKs and Azure Active Directory
44
+
45
+ Microsoft Identity SDKs major versions will maintain backwards compatibility with Azure Active Directory web services through the support period. This means that the API surface area defined in a MAJOR version will continue to work for 2 years after release.
46
+
47
+ We will respond to bugs quickly from our partners and customers submitted through GitHub and through our private alias (tellaad@microsoft.com) for security issues and update the PATCH version number. We will also submit a change summary for each PATCH number.
48
+ Occasionally, there will be security bugs or breaking bugs from our partners that will require an immediate fix and a publish of an update to all partners and customers. When this occurs, we will do an emergency roll up to a PATCH version number and update all our distribution methods to the latest.
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'rake'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ # This can be run with `bundle exec rake spec`.
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = `git ls-files`.split("\n").select { |f| f.end_with? 'spec.rb' }
10
+ t.rspec_opts = '--format documentation'
11
+ end
12
+
13
+ # This can be run with `bundle exec rake rubocop`.
14
+ RuboCop::RakeTask.new(:rubocop) do |t|
15
+ t.patterns = `git ls-files`.split("\n").select do |f|
16
+ f.end_with?('.rb') && !f.start_with?('examples')
17
+
18
+ end
19
+ t.fail_on_error = false
20
+ end
21
+
22
+ task default: :spec
@@ -0,0 +1,25 @@
1
+ *.rbc
2
+ capybara-*.html
3
+ rspec
4
+ /log
5
+ /tmp
6
+ /public/system
7
+ /coverage/
8
+ /spec/tmp
9
+ **.orig
10
+ rerun.txt
11
+ pickle-email-*.html
12
+ config/secrets.yml
13
+ config/initializers/secret_token.rb
14
+ /vendor/bundle
15
+ .rvmrc
16
+ /vendor/assets/bower_components
17
+ *.bowerrc
18
+ bower.json
19
+ .powenv
20
+ /.bundle
21
+ /db/*.sqlite3
22
+ /db/*.sqlite3-journal
23
+ /log/*
24
+ !/log/.keep
25
+ /tmp
@@ -0,0 +1,33 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '4.2.1'
4
+
5
+ # Stores the todo list.
6
+ gem 'sqlite3'
7
+
8
+ # Templating library for views.
9
+ gem 'haml'
10
+
11
+ # The actual web server.
12
+ gem 'thin'
13
+
14
+ # Rack middleware authentication framework.
15
+ gem 'omniauth'
16
+
17
+ # AzureAD specific strategy for OmniAuth.
18
+ gem 'omniauth-azure-activedirectory'
19
+
20
+ # Loads configurations from .env into ENV hash.
21
+ gem 'dotenv'
22
+
23
+ # Acquires access tokens for resources.
24
+ gem 'adal'
25
+
26
+ # For the front end.
27
+ gem 'sass-rails', '~> 5.0'
28
+ gem 'uglifier', '>= 1.3.0'
29
+ gem 'coffee-rails', '~> 4.1.0'
30
+ gem 'jquery-rails'
31
+ gem 'jbuilder', '~> 2.0'
32
+ gem 'sdoc', '~> 0.4.0', group: :doc
33
+ gem 'turbolinks'
@@ -0,0 +1,83 @@
1
+ Rails, OmniAuth and Graph API
2
+ =============================
3
+
4
+ This is a sample MVC web application that demonstrates user authentication with OmniAuth for Azure Active Directory and RESTful calls to the AzureAD Graph API with ADAL Ruby.
5
+
6
+ ## How to run this sample
7
+
8
+ To run this sample you will need
9
+ - [Ruby](https://www.ruby-lang.org/en/documentation/installation/)
10
+ - [Bundler](http://bundler.io)
11
+ - An internet connection
12
+ - An Azure subscription (a free trial is sufficient)
13
+
14
+ ### Step 1 - Install ADAL from source
15
+ Note: This can and should be removed once ADAL is available on RubyGems. After that point ADAL will be installed along with the other dependencies in step 3.
16
+
17
+ ```
18
+ git clone git@github.com:AzureAD/azure-activedirectory-library-for-ruby
19
+ cd azure-activedirectory-library-for-ruby
20
+ gem build adal.gemspec
21
+ gem install adal
22
+ ```
23
+
24
+ ### Step 2 - Install OmniAuth AzureAD from source
25
+ Note: This can and should be removed once ADAL is available on RubyGems. After that point ADAL will be installed along with the other dependencies in step 3.
26
+
27
+ ```
28
+ git clone git@github.com:AzureAD/omniauth-azure-activedirectory-priv
29
+ cd omniauth-azure-activedirectory-priv
30
+ gem build omniauth-azure-activedirectory.gemspec
31
+ gem install omniauth-azure-activedirectory
32
+ ```
33
+
34
+ ### Step 3 - Install the sample dependencies
35
+
36
+ ```
37
+ cd examples/rails-todo-list-app
38
+ bundle
39
+ ```
40
+
41
+ ### Step 4 - Set up the database
42
+
43
+ ```
44
+ rake db:schema:load
45
+ ```
46
+
47
+ Note: Depending on your host environment, you may need to install a Javascript runtime. We suggest Node.js. Installation will differ by platform.
48
+
49
+ ### Step 5 - Configure the app
50
+
51
+ Open `config/environment.rb` and replace the `CLIENT_ID`, `CLIENT_SECRET` and `TENANT` with your values.
52
+
53
+ ### Step 6 - Set up SSL
54
+
55
+ This step is optional to get the sample running and varies across platform and choice of webserver. Here we will present one set of instructions to accomplish this, but there are many others.
56
+
57
+ Generate a self-signed certificate.
58
+
59
+ ```
60
+ openssl req -new -newkey rsa:2048 -sha1 -days 365 -nodes -x509 -keyout server.key -out server.crt
61
+ ```
62
+
63
+ Get your machine/browser to trust the certificate. This varies wildly by platform.
64
+
65
+ On OSX with Safari or Chrome, double click on `server.crt` in Finder to add it to the keychain and then select 'Trust Always'. In Firefox go to Preferences > Advanced > View Certificates > Import and add `server.crt`.
66
+
67
+ ### Step 7 - Start up Rails
68
+
69
+ This sample uses the Thin webserver to host the app on port 9292.
70
+
71
+ If you generated a certificate in Step 6
72
+
73
+ ```
74
+ bundle exec thin start --port 9292 --ssl --ssl-key-file server.key --ssl-cert-file server.crt
75
+ ```
76
+
77
+ If you want to skip SSL verification (shame!)
78
+
79
+ ```
80
+ bundle exec thing start --port 9292 --ssl --ssl-disable-verify
81
+ ```
82
+
83
+ You may now proceed to https://localhost:9292 to view the application. You may get a warning about the self-signed certificate. This is nothing to worry about, as in production you will not be using self-signed certs.
@@ -0,0 +1,3 @@
1
+ require File.expand_path('../config/application', __FILE__)
2
+
3
+ Rails.application.load_tasks
@@ -0,0 +1,4 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require turbolinks
4
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ //= require_tree .
2
+ //= require_self
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -0,0 +1,2 @@
1
+ class HomeController < ApplicationController
2
+ end
@@ -0,0 +1,20 @@
1
+ class ProfileController < SignedInController
2
+
3
+ # If we have the user's ADAL credentials, then we can get an access token.
4
+ # Otherwise we need to do the auth code flow dance.
5
+ def index
6
+ @profile = user_data_hash(current_user.graph_access_token)
7
+ super
8
+ rescue ADAL::TokenRequest::UserCredentialError
9
+ redirect_to User.authorization_request_url.to_s
10
+ end
11
+
12
+ # @return Hash
13
+ def user_data_hash(access_token)
14
+ headers = { 'authorization' => access_token }
15
+ me_endpt = URI('https://graph.windows.net/me?api-version=1.5')
16
+ http = Net::HTTP.new(me_endpt.hostname, me_endpt.port)
17
+ http.use_ssl = true
18
+ JSON.parse(http.get(me_endpt, headers).body)
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ class SessionsController < ApplicationController
2
+ skip_before_filter :verify_authenticity_token
3
+
4
+ def new
5
+ redirect_to '/auth/azureactivedirectory'
6
+ end
7
+
8
+ def create
9
+ # If the session expires, they still access the same todo list next time
10
+ # that they log in with omniauth.
11
+ user = User.find_by_provider_and_uid(auth_hash['provider'],
12
+ auth_hash['uid'])
13
+ user ||= User.from_omniauth(auth_hash)
14
+ session['user_id'] = user.id
15
+ redirect_to tasks_path
16
+ end
17
+
18
+ def destroy
19
+ reset_session
20
+ redirect_to root_url
21
+ end
22
+
23
+ protected
24
+
25
+ def auth_hash
26
+ request.env['omniauth.auth']
27
+ end
28
+ end