Skip to content

Instantly share code, notes, and snippets.

View craigplummer's full-sized avatar

Craig Plummer craigplummer

View GitHub Profile
@craigplummer
craigplummer / ruby-setup-semaphore.sh
Created October 25, 2018 12:56
Semaphore Ruby Setup
#!/bin/bash
set -e
ruby_version=${1:-"2.5.3"}
gem_version=${2:-"2.7.7"}
ruby_archive="$ruby_version.tar.gz"
ruby_install_path="/home/runner/.rbenv/versions/$ruby_version"
if [ ! -e /home/runner/.rbenv ]
@craigplummer
craigplummer / sessions_controller.rb
Created July 29, 2016 16:11
Using Microsoft ADFS with Ruby on Rails and Omniauth - sessions_controller.rb#logout
def logout
reset_session
redirect_to "https://adfs.example.com/adfs/ls/?wa=wsignout1.0&wreply=https://#{request.host}"
end
@craigplummer
craigplummer / sessions_controller.rb
Created July 29, 2016 16:09
Using Microsoft ADFS with Ruby on Rails and Omniauth - sessions_controller.rb
def create
auth = request.env["omniauth.auth"]
auth.uid # Gets the UID value of the user that has just signed in
# Create a session, redirect etc
end
@craigplummer
craigplummer / routes.rb
Created July 29, 2016 16:07
Using Microsoft ADFS with Ruby on Rails and Omniauth - routes.rb
match '/auth/:provider/callback' => 'sessions#create', via: [:get, :post]
match '/auth/failure' => 'sessions#failure', via: [:get]
@craigplummer
craigplummer / omniauth.rb
Created July 29, 2016 16:01
Using Microsoft ADFS with Ruby on Rails and Omniauth - omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :wsfed,
:issuer_name => "http://adfs.example.com/adfs/services/trust",
:issuer => "https://adfs.example.com/adfs/ls/",
:realm => "https://myapp.com",
:reply => "https://myapp.com/auth/wsfed/callback",
:saml_version => "1",
:id_claim => "upn",
:idp_cert_fingerprint => "2ds.........."
end
@craigplummer
craigplummer / Gemfile
Created July 29, 2016 15:59
Using Microsoft ADFS with Ruby on Rails and Omniauth - Gemfile
gem 'omniauth'
gem 'omniauth-wsfed', '0.3.2.pre.beta'
@craigplummer
craigplummer / FederationMetadata.xml
Last active July 29, 2016 15:57
Using Microsoft ADFS with Ruby on Rails and Omniauth - FederationMetadata.xml
<?xml version="1.0" encoding="utf-8"?>
<EntityDescriptor ID="_271f377f-78d8-4133-8c46-a73c4936bb1f" entityID="https://example.com" xmlns="urn:oasis:names:tc:SAML:2.0:metadata">
<RoleDescriptor xsi:type="fed:ApplicationServiceType" xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706" protocolSupportEnumeration="http://docs.oasis-open.org/wsfed/federation/200706" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fed:TargetScopes>
<wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Address>https://example.com/</wsa:Address>
</wsa:EndpointReference>
</fed:TargetScopes>
<fed:PassiveRequestorEndpoint>
<wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing">
@craigplummer
craigplummer / warden_helper.rb
Created July 29, 2016 15:46
Using Microsoft Azure AD for API Authentication with Rails and Warden - warden_helper.rb
module WardenHelper
extend ActiveSupport::Concern
included do
helper_method :warden, :current_user
prepend_before_filter :authenticate!
end
def current_user
@craigplummer
craigplummer / warden.rb
Created July 29, 2016 15:45
Using Microsoft Azure AD for API Authentication with Rails and Warden - warden.rb
require Rails.root.join('lib/strategies/azure_ad_json_web_token_strategy')
Warden::Strategies.add(:azure_ad_json_web_token, AzureAdJsonWebTokenStrategy)
@craigplummer
craigplummer / application.rb
Created July 29, 2016 15:44
Using Microsoft Azure AD for API Authentication with Rails and Warden - application.rb
config.middleware.insert_after ActionDispatch::ParamsParser, Warden::Manager do |manager|
manager.default_strategies :azure_ad_json_web_token
manager.failure_app = UnauthorizedController
end