Skip to content

Commit e5404d8

Browse files
committed
first commit
0 parents  commit e5404d8

File tree

13 files changed

+235
-0
lines changed

13 files changed

+235
-0
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# CHANGELOG
2+
3+
### 0.1.0 - 2016-06-18
4+
5+
* Converted omniauth-office365 to omniauth-microsoft_graph - big ups to [@simi](https://github.com/simi)
6+
7+
### 0.0.1 - 2015-05-25
8+
9+
* initial version (big props to [@dayash](https://github.com/dayash))
10+

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in omniauth-office365.gemspec
4+
gemspec

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2014 Josef Šimánek
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Omniauth::MicrosoftGraph [![Build Status](https://travis-ci.org/synth/omniauth-microsoft_graph.svg?branch=master)](https://travis-ci.org/synth/omniauth-microsoft_graph)
2+
3+
Microsoft Graph OAuth2 Strategy for OmniAuth.
4+
Can be used to authenticate with Office365 or other MS services, and get a token for the Microsoft Graph Api, formerly the Office365 Unified Api.
5+
6+
## Installation
7+
8+
Add this line to your application's Gemfile:
9+
10+
```ruby
11+
gem 'omniauth-microsoft_graph'
12+
```
13+
14+
And then execute:
15+
16+
$ bundle
17+
18+
Or install it yourself as:
19+
20+
$ gem install omniauth-microsoft_graph
21+
22+
## Usage
23+
24+
```ruby
25+
Rails.application.config.middleware.use OmniAuth::Builder do
26+
provider :microsoft_graph, ENV['AZURE_APPLICATION_CLIENT_ID'], ENV['AZURE_APPLICATION_CLIENT_SECRET']
27+
end
28+
```
29+
30+
31+
## Contributing
32+
33+
1. Fork it ( https://github.com/synth/omniauth-microsoft_graph/fork )
34+
2. Create your feature branch (`git checkout -b my-new-feature`)
35+
3. Commit your changes (`git commit -am 'Add some feature'`)
36+
4. Push to the branch (`git push origin my-new-feature`)
37+
5. Create a new Pull Request

Rakefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "bundler/gem_tasks"
2+
require "rake/testtask"
3+
4+
Rake::TestTask.new(:test) do |t|
5+
t.libs << "test"
6+
t.test_files = FileList['test/*_test.rb']
7+
end
8+
9+
task :default => :test
10+

example/example.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$:.push File.dirname(__FILE__) + '/../lib'
2+
3+
require 'omniauth-microsoft_graph'
4+
require 'sinatra'
5+
require 'json'
6+
7+
set :port, 4200
8+
9+
client_id = ENV['AZURE_APPLICATION_CLIENT_ID']
10+
secret = ENV['AZURE_APPLICATION_CLIENT_SECRET']
11+
12+
use Rack::Session::Cookie
13+
use OmniAuth::Builder do
14+
provider :microsoft_graph, client_id, secret
15+
end
16+
17+
get '/' do
18+
"<a href='/auth/microsoft_graph'>Log in with Microsoft</a>"
19+
end
20+
21+
get '/auth/microsoft_graph/callback' do
22+
content_type 'text/plain'
23+
request.env['omniauth.auth'].to_json
24+
end
25+
26+
get '/auth/failure' do
27+
content_type 'text/plain'
28+
params.to_json
29+
end

lib/microsoft_graph.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'omniauth/microsoft_graph'

lib/omniauth/microsoft_graph.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "omniauth/microsoft_graph/version"
2+
require "omniauth/strategies/microsoft_graph"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Omniauth
2+
module Office365
3+
VERSION = "0.1.0"
4+
end
5+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'omniauth-oauth2'
2+
3+
module OmniAuth
4+
module Strategies
5+
class MicrosoftGraph < OmniAuth::Strategies::OAuth2
6+
option :name, :microsoft_graph
7+
8+
option :client_options, {
9+
site: 'https://login.microsoftonline.com/common/oauth2/authorize',
10+
token_url: 'https://login.microsoftonline.com/common/oauth2/token',
11+
authorize_url: 'https://login.microsoftonline.com/common/oauth2/authorize'
12+
}
13+
14+
option :authorize_params, {
15+
resource: 'https://graph.microsoft.com/'
16+
}
17+
18+
option :token_params, {
19+
resource: 'https://graph.microsoft.com/'
20+
}
21+
22+
uid { raw_info["id"] }
23+
24+
info do
25+
{
26+
'email' => raw_info["mail"],
27+
'first_name' => raw_info["givenName"],
28+
'last_name' => raw_info["surname"],
29+
'name' => [raw_info["givenName"], raw_info["surname"]].join(' '),
30+
'nickname' => raw_info["displayName"],
31+
}
32+
end
33+
34+
extra do
35+
{
36+
'raw_info' => raw_info,
37+
'params' => access_token.params
38+
}
39+
end
40+
41+
def raw_info
42+
@raw_info ||= access_token.get(authorize_params.resource + 'v1.0/me').parsed
43+
end
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)