Initial commit

This commit is contained in:
Eugen Rochko 2016-10-22 01:45:58 +02:00
commit e99e83fe90
7 changed files with 129 additions and 0 deletions

3
Gemfile Normal file
View File

@ -0,0 +1,3 @@
source 'https://rubygems.org'
gemspec

40
Gemfile.lock Normal file
View File

@ -0,0 +1,40 @@
PATH
remote: .
specs:
omniauth-mastodon (0.0.1)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)
GEM
remote: https://rubygems.org/
specs:
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
hashie (3.4.6)
jwt (1.5.6)
multi_json (1.12.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
oauth2 (1.2.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
omniauth (1.3.1)
hashie (>= 1.2, < 4)
rack (>= 1.0, < 3)
omniauth-oauth2 (1.4.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
rack (2.0.1)
PLATFORMS
ruby
DEPENDENCIES
bundler (~> 1.0)
omniauth-mastodon!
BUNDLED WITH
1.13.0

2
README.md Normal file
View File

@ -0,0 +1,2 @@
OmniAuth::Mastodon
==================

2
lib/omniauth-mastodon.rb Normal file
View File

@ -0,0 +1,2 @@
require 'omniauth/mastodon/version'
require 'omniauth/strategies/mastodon'

View File

@ -0,0 +1,31 @@
module OmniAuth
module Mastodon
module Version
module_function
def major
0
end
def minor
0
end
def patch
1
end
def pre
nil
end
def to_a
[major, minor, patch, pre].compact
end
def to_s
to_a.join('.')
end
end
end
end

View File

@ -0,0 +1,30 @@
require 'omniauth-oauth2'
module OmniAuth
module Strategies
class Mastodon < OmniAuth::Strategies::OAuth2
option :name, 'mastodon'
option :domain
uid { [raw_info['username'], '@', options.domain].join }
info do
{
name: raw_info['username'],
nickname: raw_info['username'],
image: raw_info['avatar'],
urls: { 'Profile' => raw_info['url'] }
}
end
extra do
{ raw_info: raw_info }
end
def raw_info
@raw_info ||= access_token.get('api/v1/accounts/verify_credentials').parsed
end
end
end
end

21
omniauth-mastodon.gemspec Normal file
View File

@ -0,0 +1,21 @@
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'omniauth/mastodon/version'
Gem::Specification.new do |spec|
spec.authors = ["Eugen Rochko"]
spec.email = "eugen@zeonfederated.com"
spec.description = "OmniAuth Strategy for Mastodon"
spec.summary = spec.description
spec.homepage = "https://github.com/Gargron/omniauth-mastodon"
spec.licenses = %w(MIT)
spec.files = %w(omniauth-mastodon.gemspec) + Dir['lib/**/*.rb']
spec.name = "omniauth-mastodon"
spec.require_paths = %w(lib)
spec.version = OmniAuth::Mastodon::Version
spec.add_dependency 'omniauth', '~> 1.0'
spec.add_dependency 'omniauth-oauth2', '~> 1.1'
spec.add_development_dependency 'bundler', '~> 1.0'
end