Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • msu-middleware-group/omniauth-msunet
  • perrych2/omniauth-msunet
2 results
Show changes
Commits on Source (49)
language: ruby
rvm:
- 2.1
- 2.2
- 2.3.0
before_install: gem update bundler
script: bundle exec rspec
deploy:
provider: rubygems
api_key:
secure: Fw1W/gJ4kyphhm9nZsOA99RKtDUbgAO3PTI2hVIW/WQLqbhry1QIOFNgtoYRnPAcLvKWNEjhYHf3lLtEqR89yHtoL3nJult3VX/m1Ej7+akdDZ+Ab5LQ5WEFJLD+hwH+D3DkVEQLa1hl6fWfb88jvcvZ2+Q3VcD32pCnNTzTOJeO9p5SjlIuEG58FXS6FtpcspvH54hKXmR8XSuKTyCb4XeA1cGwUdr+n+YvZIk08f6jTHorUejlX2LjMuxS81UY9JEGun3AOz/ITF9Tca3aMEkONVBzncfmhPeWMqijqESbYk2FpGiTsD6NTBYuZtKxlwXyhspy0aC9V0aM8An4EPYhKrD2MM77EsQWQU2r5uE7Nx3t1BU5Qxc5UAKdC08+B7tK0HnduFadOxcYwiWPunj3AOur4pZCTNs1NB/4p+tqEWe/d+NBhIRc+ty8LexrQ6pxMPnRhlylkthQ6eTUhikVNN7Thylb9Fa1eFeTNhe+RF53Z/WsNj7s35yDFLa8n9JMnlMOf3ITn3F/GA7ykObk93uGCGaNgMuVgkIPTeh+IGINy4jQ+IYRYEtRVF5DaYODcLycpIIsG2ifpJgHm32sFP7aPhIQXCsdtlSHMwhj4lakgTVO52rthRy6dSH1Bt6f76STzzOuVVYjCQWyJ9rRraQlCn8ZDdVvEWh9fvo=
on:
tags: true
### 1.0.0
# Changelog
Bug fixes
## 1.1.0
None
* Change service hostname from oauth.ais.msu.edu to oauth.itservices.msu.edu
Enhancements
## 1.0.2
None
* Clean-up some code and formatting
* Add some specs
## 1.0.1
* Rename netid field to msunetid
## 1.0.0
* Add netid field
* Update gem to use production MSUnet OAuth2 provider
## 0.5.0
* Initial release
source 'http://rubygems.org'
# Specify your gem's dependencies in omniauth-msunet.gemspec
gemspec
gem 'rack', '< 2.0.1', platform: :ruby_21
group :development, :test do
gem 'guard'
gem 'guard-rspec'
gem 'guard-bundler'
gem 'rb-fsevent'
gem 'growl'
end
gemspec
# OmniAuth MSUnet
# OmniAuth MSU NetID
This is the official OmniAuth strategy for authenticating to [Michigan State University](http://www.msu.edu) MSUnet. To
use it, you'll need to sign up for an OAuth2 Application ID and Secret
on the [MSUnet Applications Page](https://oauth.msu.edu/settings/applications).
[![Build Status](https://travis-ci.org/Michigan-State-University/omniauth-msunet.svg?branch=master)](https://travis-ci.org/Michigan-State-University/omniauth-msunet)
[![Dependency Status](https://gemnasium.com/Michigan-State-University/omniauth-oauth2.svg)](https://gemnasium.com/Michigan-State-University/omniauth-oauth2)
## Description
This is the official OmniAuth strategy gem for authenticating to [Michigan State University](https://msu.edu) MSU NetID using OAuth2. To use this gem you'll need the following:
* Contact MSU Information Technology Service Desk at 517-432-6200 to request to register your application, or complete the [OAuth 2.0 request form] (https://tech.msu.edu/network/authentication-authorization)
* Provide MSU Information Technology Identity Management with a callback URL, which is where to send successful MSU NetID authentication requests back to your application. Note: this must be a HTTPS address.
* Receive a `client_id` token and `client_secret` token specific for your application.
## Installation
To install this gem you need to use ``gem install omniauth-msunet --pre``
To install this gem you need to add it to your Gemfile as follows:
```gem 'omniauth-msunet'```
## Basic Usage
use OmniAuth::Builder do
provider :msunet, ENV['MSUNET_KEY'], ENV['MSUNET_SECRET']
end
If this is your applications first OmniAuth strategy then you will need to create the file config/initializers/omniauth.rb, otherwise update your existing one.
## License
```
Rails.application.config.middleware.use OmniAuth::Builder do
provider :msunet, "replace_with_client_id", "replace_with_client_secret"
end
```
Next you need to setup some routes to handle the callback and if it's a success or failure. You could use something like the following in your config/routes.rb file
```
match 'auth/:provider/callback', to: 'sessions#create'
match 'auth/failure', to: redirect('/')
match 'signout', to: 'sessions#destroy', as: 'signout'
```
Finally restart your server for all of the changes to take effect. You can now browse to your apps URL `https://0.0.0.0/auth/msunet` to login.
Once the login is completed you should receive the following hash that you can access:
```
{
"provider":"msunet",
"uid":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"info":{
"name":"John Sparty",
"email":"sparty@msu.edu",
"first_name":"John",
"last_name":"Sparty",
"description":"MSU NetID OAuth2 Auth-n"
}
}
```
TODO: Add license from MSU General Counsel & MSU Intellectual Property Office.
## Development
1) Clone the repository
2) Write some tests
3) Make them pass
4) Request a pull
### Testing
`bundle exec rspec`
### Releasing
Use the [version](https://github.com/stouset/version) gem. See `bundle exec
rake -T version` for commands. Bumping the version will change the `VERSION`
file, commit the changes, and create a tag. You can then push the tag to your
remote:
```
bundle exec rake version:bump # create a minor version bump
git push # push code changes
git push origin $(bundle exec rake version) # push new tag
```
## License
Please see the LICENSE.md file.
require 'rake/version_task'
Rake::VersionTask.new do |task|
task.with_git_tag = true
end
1.1.0
require "omniauth-msunet/version"
require 'omniauth-oauth2'
require 'omniauth/strategies/msunet'
module OmniAuth
module Msunet
VERSION = "1.0.0.alpha1"
end
end
require 'omniauth-oauth2'
require 'multi_json'
module OmniAuth
module Strategies
class Msunet < OmniAuth::Strategies::OAuth2
class MSUnet < OmniAuth::Strategies::OAuth2
option :client_options, {
:site => 'http://oauth-server.dev',
#:site => 'oauth.dev.ais.msu.edu',
:authorize_url => 'http://oauth-server.dev/oauth/authorize'
#,:token_url => 'https://oauth.dev.ais.msu.edu/oauth/access_token'
site: "https://oauth.itservices.msu.edu",
authorize_url: "/oauth/authorize",
token_url: "/oauth/token"
}
def request_phase
super
uid do
raw_info['uid'].to_s
end
def authorize_params
super.tap do |params|
%w[scope client_options].each do |v|
if request.params[v]
params[v.to_sym] = request.params[v]
end
end
end
end
uid { raw_info['id'].to_s }
info do
{
'uid' => raw_info['login'],
'email' => email,
'name' => raw_info['name'],
name: raw_info['info']['name'].to_s || raw_info['name'].to_s,
first_name: raw_info['info']['first_name'].to_s || raw_info['first_name'].to_s,
last_name: raw_info['info']['last_name'].to_s || raw_info['last_name'].to_s,
email: raw_info['info']['email'].to_s || raw_info['email'].to_s,
msunetid: raw_info['info']['msunetid'].to_s || raw_info['msunetid'].to_s
}
end
extra do
{:raw_info => raw_info}
{ raw_info: raw_info }
end
def raw_info
access_token.options[:mode] = :query
@raw_info ||= access_token.get('user').parsed
end
def email
(raw_info['email'].nil? || raw_info['email'].empty?) ? primary_email : raw_info['email']
end
def primary_email
primary = emails.find{|i| i['primary'] }
primary && primary['email'] || emails.first && emails.first['email']
end
def email_access_allowed?
options['scope'] =~ /user/
@raw_info ||= MultiJson.load(access_token.get("/oauth/me?access_token=#{access_token.token}").body)
end
end
end
end
OmniAuth.config.add_camelization 'msunet', 'Msunet'
OmniAuth.config.add_camelization 'msunet', 'MSUnet'
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/omniauth-msunet/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Troy Murray"]
gem.email = ["tm@msu.edu"]
gem.summary = %q{Official OmniAuth strategy for Michigan State University MSUnet.}
gem.description = %q{Official OmniAuth strategy for Michigan State University MSUnet.}
gem.homepage = "https://github.com/tdm00/omniauth-msunet"
gem.name = 'omniauth-msunet'
gem.summary = %q{Michigan State University MSUnet OmniAuth strategy.}
gem.description = %q{Official OmniAuth strategy for authenticating against the Michigan State University MSUnet OAuth2 provider.}
gem.version = File.read('VERSION')
gem.homepage = "https://gitlab.msu.edu/msu-middleware-group/omniauth-msunet"
gem.license = 'Nonstandard'
gem.authors = ['Troy Murray', 'Andrew Tomaka']
gem.email = ['tm@msu.edu', 'atomaka@msu.edu']
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.name = "omniauth-msunet"
gem.require_paths = ["lib"]
gem.version = OmniAuth::Msunet::VERSION
gem.add_dependency 'omniauth', '~> 1.0'
gem.add_dependency 'omniauth', '~> 1.1'
gem.add_dependency 'omniauth-oauth2', '~> 1.1'
gem.add_development_dependency 'rspec', '~> 2.7'
gem.add_development_dependency 'rack-test'
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'webmock'
gem.add_dependency 'multi_json', '~> 1.7'
gem.add_development_dependency 'rspec', '~> 3.4'
gem.add_development_dependency 'rake', '~> 10.4'
gem.add_development_dependency 'version'
end
require 'spec_helper'
require 'omniauth-msunet'
describe OmniAuth::Strategies::MSUnet do
let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
let(:app) { lambda { [200, {}, ["Hello."]] } }
subject do
OmniAuth::Strategies::MSUnet.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
allow(strategy).to receive(:request) { request }
end
end
before do
OmniAuth.config.test_mode = true
end
after do
OmniAuth.config.test_mode = false
end
describe '#client_options' do
it 'has correct site' do
expect(subject.client.site).to eq('https://oauth.itservices.msu.edu')
end
it 'has correct authorize_url' do
expect(subject.client.options[:authorize_url]).to eq('/oauth/authorize')
end
it 'has correct token_url' do
expect(subject.client.options[:token_url]).to eq('/oauth/token')
end
context 'overrides' do
it 'should allow overriding the site' do
@options = { client_options: { site: 'https://domain.com' }}
expect(subject.client.site).to eq('https://domain.com')
end
it 'should allow overriding the authorize_url' do
@options = { client_options: { authorize_url: 'https://domain.com' }}
expect(subject.client.authorize_url).to eq('https://domain.com')
end
it 'should allow overriding the token_url' do
@options = { client_options: { token_url: 'https://domain.com' }}
expect(subject.client.token_url).to eq('https://domain.com')
end
end
end
describe '#extra' do
let(:client) do
OAuth2::Client.new('abc', 'def') do |builder|
builder.request :url_encoded
builder.adapter :test do |stub|
stub.get('/oauth/me?access_token=') {|env| [200, {'content-type' => 'application/json'}, '{"email": "user@domain.com"}']}
end
end
end
let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
before { allow(subject).to receive(:access_token).and_return(access_token) }
describe '#raw_info' do
it 'should include raw_info' do
expect(subject.raw_info).to eq('email' => 'user@domain.com')
end
end
end
describe '#callback_path' do
it 'has the correct default callback path' do
expect(subject.callback_path).to eq('/auth/msunet/callback')
end
it 'should set the callback_path parameter if present' do
@options = {callback_path: '/login'}
expect(subject.callback_path).to eq('/login')
end
end
end
require File.join('bundler', 'setup')
require 'rspec'