From e99e83fe90e877f4a02a9de6bd4574af44864121 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 22 Oct 2016 01:45:58 +0200 Subject: [PATCH] Initial commit --- Gemfile | 3 +++ Gemfile.lock | 40 +++++++++++++++++++++++++++++ README.md | 2 ++ lib/omniauth-mastodon.rb | 2 ++ lib/omniauth/mastodon/version.rb | 31 ++++++++++++++++++++++ lib/omniauth/strategies/mastodon.rb | 30 ++++++++++++++++++++++ omniauth-mastodon.gemspec | 21 +++++++++++++++ 7 files changed, 129 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 README.md create mode 100644 lib/omniauth-mastodon.rb create mode 100644 lib/omniauth/mastodon/version.rb create mode 100644 lib/omniauth/strategies/mastodon.rb create mode 100644 omniauth-mastodon.gemspec diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..fa75df1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..6881f85 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..c1995c9 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +OmniAuth::Mastodon +================== diff --git a/lib/omniauth-mastodon.rb b/lib/omniauth-mastodon.rb new file mode 100644 index 0000000..005f5e5 --- /dev/null +++ b/lib/omniauth-mastodon.rb @@ -0,0 +1,2 @@ +require 'omniauth/mastodon/version' +require 'omniauth/strategies/mastodon' diff --git a/lib/omniauth/mastodon/version.rb b/lib/omniauth/mastodon/version.rb new file mode 100644 index 0000000..22d0095 --- /dev/null +++ b/lib/omniauth/mastodon/version.rb @@ -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 diff --git a/lib/omniauth/strategies/mastodon.rb b/lib/omniauth/strategies/mastodon.rb new file mode 100644 index 0000000..58a4aa3 --- /dev/null +++ b/lib/omniauth/strategies/mastodon.rb @@ -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 diff --git a/omniauth-mastodon.gemspec b/omniauth-mastodon.gemspec new file mode 100644 index 0000000..6a50e00 --- /dev/null +++ b/omniauth-mastodon.gemspec @@ -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