authorization-endpoint 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +14 -0
- data/.gitignore +34 -0
- data/.rspec +2 -0
- data/.rubocop +3 -0
- data/.rubocop.yml +15 -0
- data/.ruby-version +1 -0
- data/.simplecov +11 -0
- data/.travis.yml +19 -0
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +37 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +104 -0
- data/Rakefile +6 -0
- data/authorization-endpoint.gemspec +36 -0
- data/lib/authorization_endpoint.rb +16 -0
- data/lib/authorization_endpoint/client.rb +19 -0
- data/lib/authorization_endpoint/discover.rb +63 -0
- data/lib/authorization_endpoint/error.rb +13 -0
- data/lib/authorization_endpoint/response.rb +27 -0
- data/lib/authorization_endpoint/version.rb +3 -0
- metadata +268 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3629250c7917694bf3539fef3018d181c56536d0
|
4
|
+
data.tar.gz: aced79fce8e4639f82d1580f47cc71e0842f2922
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1da86df1986001c5401d6ab7c31ab7161766941f285440f8a5f5ec8e52c0e9be0a9a4156f34aa4411e6bc5831e2bf6ac3fac0d1bf557989a89fe8e5e46cfd13
|
7
|
+
data.tar.gz: 6cf49ce5c85574c15e9e26f0eb98edec0ef949b0e0ce5f4b69eeaeb31d795638389069dc75528133dce0d99dc96b5d717ddb51a4ad378174ca63e0c58e1ec866
|
data/.editorconfig
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# EditorConfig is awesome: http://EditorConfig.org
|
2
|
+
root = true
|
3
|
+
|
4
|
+
[*]
|
5
|
+
charset = utf-8
|
6
|
+
end_of_line = lf
|
7
|
+
insert_final_newline = true
|
8
|
+
indent_size = 2
|
9
|
+
indent_style = space
|
10
|
+
trim_trailing_whitespace = true
|
11
|
+
|
12
|
+
[*.md]
|
13
|
+
indent_size = 4
|
14
|
+
indent_style = tab
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Documentation cache and generated files:
|
17
|
+
/.yardoc/
|
18
|
+
/_yardoc/
|
19
|
+
/doc/
|
20
|
+
/rdoc/
|
21
|
+
|
22
|
+
# Environment normalization:
|
23
|
+
/.bundle/
|
24
|
+
/vendor/bundle
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.rspec
ADDED
data/.rubocop
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.4
|
data/.simplecov
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'simplecov-console'
|
2
|
+
|
3
|
+
formatters = [SimpleCov::Formatter::HTMLFormatter]
|
4
|
+
|
5
|
+
if RSpec.configuration.files_to_run.length > 1
|
6
|
+
formatters << SimpleCov::Formatter::Console
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.start do
|
10
|
+
formatter SimpleCov::Formatter::MultiFormatter.new(formatters)
|
11
|
+
end
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.4.4
|
4
|
+
- 2.5.1
|
5
|
+
cache: bundler
|
6
|
+
before_script:
|
7
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
8
|
+
- chmod +x ./cc-test-reporter
|
9
|
+
- ./cc-test-reporter before-build
|
10
|
+
script:
|
11
|
+
- bundle exec rubocop
|
12
|
+
- bundle exec rake
|
13
|
+
after_script:
|
14
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
15
|
+
notifications:
|
16
|
+
email: false
|
17
|
+
slack:
|
18
|
+
rooms:
|
19
|
+
secure: XpiZ3HWJ8xedheVbhVL5eyIbj2zng27X/to6X3dMPJqQuSkGvgT5UQtF4kTmx0gkwHnHsP85VZvoHGpkrD6qOtPLSpWgs8CmtC6nJyqGUTTBCmjAzd7X7gQ+n4ahbCfao6z53OqLPbxLYonSAx0XbYh4SKCsWKUVubamzFIdR571ScCzrbidoycIY5VL5tePp7rah1HxcQXLWaPwY/v6kC3BoQkbEPhWKS2f4wZLQFV8NlJkHEZZkYxuht+u1pvuWQqE68HTVAp3mcfYJbwU7zynjZNcKF8AfaXeg17M3pxBsC2dJjXIpwrQW0kSmA0int0w0N1w5noPKiQ0aGMHITsXjeGt4LpAo9tv22hQhu/rnTLut2HgzhVI/5WD3VraRFAMlO6u/4tkjMQU66jauaUCfnQsp++CUMXOMdzU6KjOLp8hyppcK8PrQF9QurLBd/DqDMIOFwdipwT8p5Ll/08mAdh+AdyoAYzsg3jy2Tvb533MB1itBlacTQ2C1n/qoDdL31zyeeGO3yuHsybZ6VwZ3SvP5nglENx1x7EwIExdQWxFZBUSgmQekQMz+4GdvZw01dlFaDfGrEkQmX/l7mwL7RLyUlSJ0CXTKdp4liDTZLfpZIekgK3bvDY8qPWtvMMX+q4yPFuDBvfiN0JyQS1WGZBthFDGo/3Bjs7GEGU=
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Contributing to authorization-endpoint-ruby
|
2
|
+
|
3
|
+
There are a couple ways you can help improve authorization-endpoint-ruby:
|
4
|
+
|
5
|
+
1. Fix an existing [issue][issues] and submit a [pull request][pulls].
|
6
|
+
1. Review open [pull requests][pulls].
|
7
|
+
1. Report a new [issue][issues]. _Only do this after you've made sure the behavior or problem you're observing isn't already documented in an open issue._
|
8
|
+
|
9
|
+
## Getting Started
|
10
|
+
|
11
|
+
authorization-endpoint-ruby is developed using Ruby 2.4.4 and is additionally tested against Ruby 2.5.1 using [Travis CI](https://travis-ci.com/jgarber623/authorization-endpoint-ruby).
|
12
|
+
|
13
|
+
Before making changes to authorization-endpoint-ruby, you'll want to install Ruby 2.4.4. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm). Once you've installed Ruby 2.4.4 using your method of choice, install the project's gems by running:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
## Making Changes
|
20
|
+
|
21
|
+
1. Fork and clone the project's repo.
|
22
|
+
1. Install development dependencies as outlined above.
|
23
|
+
1. Create a feature branch for the code changes you're looking to make: `git checkout -b my-new-feature`.
|
24
|
+
1. _Write some code!_
|
25
|
+
1. If your changes would benefit from testing, add the necessary tests and verify everything passes by running `bundle exec rspec`.
|
26
|
+
1. Commit your changes: `git commit -am 'Add some new feature or fix some issue'`. _(See [this excellent article](https://chris.beams.io/posts/git-commit/) for tips on writing useful Git commit messages.)_
|
27
|
+
1. Push the branch to your fork: `git push -u origin my-new-feature`.
|
28
|
+
1. Create a new [pull request][pulls] and we'll review your changes.
|
29
|
+
|
30
|
+
## Code Style
|
31
|
+
|
32
|
+
Code formatting conventions are defined in the `.editorconfig` file which uses the [EditorConfig](http://editorconfig.org) syntax. There are [plugins for a variety of editors](http://editorconfig.org/#download) that utilize the settings in the `.editorconfig` file. We recommended you install the EditorConfig plugin for your editor of choice.
|
33
|
+
|
34
|
+
Your bug fix or feature addition won't be rejected if it runs afoul of any (or all) of these guidelines, but following the guidelines will definitely make everyone's lives a little easier.
|
35
|
+
|
36
|
+
[issues]: https://github.com/jgarber623/authorization-endpoint-ruby/issues
|
37
|
+
[pulls]: https://github.com/jgarber623/authorization-endpoint-ruby/pulls
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jason Garber
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# authorization-endpoint-ruby
|
2
|
+
|
3
|
+
**A Ruby gem for discovering a URL’s [authorization endpoint](https://indieweb.org/authorization-endpoint) for use with [Micropub](https://indieweb.org/Micropub) and [IndieAuth](https://indieweb.org/IndieAuth) clients.**
|
4
|
+
|
5
|
+
[![Gem](https://img.shields.io/gem/v/authorization-endpoint.svg?style=for-the-badge)](https://rubygems.org/gems/authorization-endpoint)
|
6
|
+
[![Downloads](https://img.shields.io/gem/dt/authorization-endpoint.svg?style=for-the-badge)](https://rubygems.org/gems/authorization-endpoint)
|
7
|
+
[![Build](https://img.shields.io/travis/com/jgarber623/authorization-endpoint-ruby/master.svg?style=for-the-badge)](https://travis-ci.com/jgarber623/authorization-endpoint-ruby)
|
8
|
+
[![Dependencies](https://img.shields.io/depfu/jgarber623/authorization-endpoint-ruby.svg?style=for-the-badge)](https://depfu.com/github/jgarber623/authorization-endpoint-ruby)
|
9
|
+
[![Maintainability](https://img.shields.io/codeclimate/maintainability/jgarber623/authorization-endpoint-ruby.svg?style=for-the-badge)](https://codeclimate.com/github/jgarber623/authorization-endpoint-ruby)
|
10
|
+
[![Coverage](https://img.shields.io/codeclimate/c/jgarber623/authorization-endpoint-ruby.svg?style=for-the-badge)](https://codeclimate.com/github/jgarber623/authorization-endpoint-ruby/code)
|
11
|
+
|
12
|
+
## Key Features
|
13
|
+
|
14
|
+
- Uses the same discovery algorithm outlined in [Section 5.3](https://www.w3.org/TR/micropub/#endpoint-discovery) of [the W3C's Micropub Recommendation](https://www.w3.org/TR/micropub/).
|
15
|
+
- Supports Ruby 2.4 and newer.
|
16
|
+
|
17
|
+
## Getting Started
|
18
|
+
|
19
|
+
Before installing and using authorization-endpoint-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.4 (or newer) installed. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm).
|
20
|
+
|
21
|
+
authorization-endpoint-ruby is developed using Ruby 2.4.4 and is additionally tested against Ruby 2.5.1 using [Travis CI](https://travis-ci.com/jgarber623/authorization-endpoint-ruby).
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
If you're using [Bundler](https://bundler.io), add authorization-endpoint-ruby to your project's `Gemfile`:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
source 'https://rubygems.org'
|
29
|
+
|
30
|
+
gem 'authorization-endpoint'
|
31
|
+
```
|
32
|
+
|
33
|
+
…and hop over to your command prompt and run…
|
34
|
+
|
35
|
+
```sh
|
36
|
+
$ bundle install
|
37
|
+
```
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
### Basic Usage
|
42
|
+
|
43
|
+
With authorization-endpoint-ruby added to your project's `Gemfile` and installed, you may discover a URL's authorization endpoint by doing:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'authorization-endpoint'
|
47
|
+
|
48
|
+
endpoint = AuthorizationEndpoint.discover('https://aaronparecki.com')
|
49
|
+
|
50
|
+
puts endpoint # returns String: 'https://aaronparecki.com/auth'
|
51
|
+
```
|
52
|
+
|
53
|
+
This example will search `https://aaronparecki.com` for a valid authorization endpoint using the same rules described in [the W3C's Micropub Recommendation](https://www.w3.org/TR/micropub/#endpoint-discovery). In this case, the program returns a string: `https://aaronparecki.com/auth`.
|
54
|
+
|
55
|
+
If no endpoint is discovered at the provided URL, the program will return `nil`:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require 'authorization-endpoint'
|
59
|
+
|
60
|
+
endpoint = AuthorizationEndpoint.discover('https://example.com')
|
61
|
+
|
62
|
+
puts endpoint.nil? # returns Boolean: true
|
63
|
+
```
|
64
|
+
|
65
|
+
### Advanced Usage
|
66
|
+
|
67
|
+
Should the need arise, you may work directly with the `AuthorizationEndpoint::Client` class:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
require 'authorization-endpoint'
|
71
|
+
|
72
|
+
client = AuthorizationEndpoint::Client.new('https://aaronparecki.com')
|
73
|
+
|
74
|
+
puts client.response # returns HTTP::Response
|
75
|
+
puts client.endpoint # returns String: 'https://aaronparecki.com/auth'
|
76
|
+
```
|
77
|
+
|
78
|
+
### Exception Handling
|
79
|
+
|
80
|
+
There are several exceptions that may be raised by authorization-endpoint-ruby's underlying dependencies. These errors are raised as subclasses of `AuthorizationEndpoint::Error` (which itself is a subclass of `StandardError`).
|
81
|
+
|
82
|
+
From [jgarber623/absolutely](https://github.com/jgarber623/absolutely) and [sporkmonger/addressable](https://github.com/sporkmonger/addressable):
|
83
|
+
|
84
|
+
- `AuthorizationEndpoint::InvalidURIError`
|
85
|
+
|
86
|
+
From [httprb/http](https://github.com/httprb/http):
|
87
|
+
|
88
|
+
- `AuthorizationEndpoint::ConnectionError`
|
89
|
+
- `AuthorizationEndpoint::TimeoutError`
|
90
|
+
- `AuthorizationEndpoint::TooManyRedirectsError`
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
Interested in helping improve authorization-endpoint-ruby? Awesome! Your help is greatly appreciated. See [CONTRIBUTING.md](https://github.com/jgarber623/authorization-endpoint-ruby/blob/master/CONTRIBUTING.md) for details.
|
95
|
+
|
96
|
+
## Acknowledgments
|
97
|
+
|
98
|
+
authorization-endpoint-ruby wouldn't exist without Micropub and the hard work put in by everyone involved in the [IndieWeb](https://indieweb.org) movement.
|
99
|
+
|
100
|
+
authorization-endpoint-ruby is written and maintained by [Jason Garber](https://sixtwothree.org).
|
101
|
+
|
102
|
+
## License
|
103
|
+
|
104
|
+
authorization-endpoint-ruby is freely available under the [MIT License](https://opensource.org/licenses/MIT). Use it, learn from it, fork it, improve it, change it, tailor it to your needs.
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'authorization_endpoint/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.required_ruby_version = ['>= 2.4', '< 2.6']
|
8
|
+
|
9
|
+
spec.name = 'authorization-endpoint'
|
10
|
+
spec.version = AuthorizationEndpoint::VERSION
|
11
|
+
spec.authors = ['Jason Garber']
|
12
|
+
spec.email = ['jason@sixtwothree.org']
|
13
|
+
|
14
|
+
spec.summary = 'Discover a URL’s authorization endpoint for use with Micropub and IndieAuth clients.'
|
15
|
+
spec.description = spec.summary
|
16
|
+
spec.homepage = 'https://github.com/jgarber623/authorization-endpoint-ruby'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|spec)/}) }
|
20
|
+
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.2'
|
24
|
+
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.1'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.7'
|
26
|
+
spec.add_development_dependency 'rubocop', '~> 0.58.1'
|
27
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.27'
|
28
|
+
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
29
|
+
spec.add_development_dependency 'simplecov-console', '~> 0.4.2'
|
30
|
+
spec.add_development_dependency 'webmock', '~> 3.4', '>= 3.4.2'
|
31
|
+
|
32
|
+
spec.add_runtime_dependency 'absolutely', '~> 1.1'
|
33
|
+
spec.add_runtime_dependency 'addressable', '~> 2.5', '>= 2.5.2'
|
34
|
+
spec.add_runtime_dependency 'http', '~> 3.3'
|
35
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.8', '>= 1.8.4'
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'absolutely'
|
2
|
+
require 'addressable/uri'
|
3
|
+
require 'http'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
require 'authorization_endpoint/version'
|
7
|
+
require 'authorization_endpoint/error'
|
8
|
+
require 'authorization_endpoint/client'
|
9
|
+
require 'authorization_endpoint/discover'
|
10
|
+
require 'authorization_endpoint/response'
|
11
|
+
|
12
|
+
module AuthorizationEndpoint
|
13
|
+
def self.discover(url)
|
14
|
+
Client.new(url).endpoint
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module AuthorizationEndpoint
|
2
|
+
class Client
|
3
|
+
def initialize(url)
|
4
|
+
raise ArgumentError, "url must be a String (given #{url.class.name})" unless url.is_a?(String)
|
5
|
+
|
6
|
+
@uri = Addressable::URI.parse(url)
|
7
|
+
rescue Addressable::URI::InvalidURIError => error
|
8
|
+
raise InvalidURIError, error
|
9
|
+
end
|
10
|
+
|
11
|
+
def endpoint
|
12
|
+
@endpoint ||= Discover.new(response).endpoint
|
13
|
+
end
|
14
|
+
|
15
|
+
def response
|
16
|
+
@response ||= Response.new(@uri).response
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module AuthorizationEndpoint
|
2
|
+
class Discover
|
3
|
+
# Ultra-orthodox pattern matching allowed values in HTTP Link header `rel` parameter
|
4
|
+
# https://tools.ietf.org/html/rfc8288#section-3.3
|
5
|
+
REGEXP_REG_REL_TYPE_PATTERN = '[a-z\d][a-z\d\-\.]*'.freeze
|
6
|
+
|
7
|
+
# Liberal pattern matching a string of text between angle brackets
|
8
|
+
# https://tools.ietf.org/html/rfc5988#section-5.1
|
9
|
+
REGEXP_TARGET_URI_PATTERN = /^<(.*)>;/
|
10
|
+
|
11
|
+
# Ultra-orthodox pattern matching HTTP Link header `rel` parameter including an `authorization_endpoint` value
|
12
|
+
# https://www.w3.org/TR/indieauth/#x4-discovery
|
13
|
+
REGEXP_AUTHORIZATION_ENDPOINT_REL_PATTERN = /(?:;|\s)rel="?(?:#{REGEXP_REG_REL_TYPE_PATTERN}+\s)?authorization_endpoint(?:\s#{REGEXP_REG_REL_TYPE_PATTERN})?"?/
|
14
|
+
|
15
|
+
def initialize(response)
|
16
|
+
raise ArgumentError, "response must be an HTTP::Response (given #{response.class.name})" unless response.is_a?(HTTP::Response)
|
17
|
+
|
18
|
+
@response = response
|
19
|
+
end
|
20
|
+
|
21
|
+
def endpoint
|
22
|
+
return unless endpoint_from_http_request
|
23
|
+
|
24
|
+
@endpoint ||= Absolutely.to_absolute_uri(base: @response.uri.to_s, relative: endpoint_from_http_request)
|
25
|
+
rescue Absolutely::InvalidURIError => error
|
26
|
+
raise InvalidURIError, error
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def endpoint_from_body
|
32
|
+
return unless @response.mime_type == 'text/html'
|
33
|
+
|
34
|
+
doc = Nokogiri::HTML(@response.body.to_s)
|
35
|
+
|
36
|
+
# Search response body for first `link` element with valid `rel` attribute
|
37
|
+
link_element = doc.css('link[rel~="authorization_endpoint"][href]').shift
|
38
|
+
|
39
|
+
return link_element['href'] if link_element
|
40
|
+
end
|
41
|
+
|
42
|
+
def endpoint_from_headers
|
43
|
+
link_headers = @response.headers.get('link')
|
44
|
+
|
45
|
+
return unless link_headers
|
46
|
+
|
47
|
+
# Split Link headers with multiple values, flatten the resulting array, and strip whitespace
|
48
|
+
link_headers = link_headers.map { |header| header.split(',') }.flatten.map(&:strip)
|
49
|
+
|
50
|
+
authorization_endpoint_header = link_headers.find { |header| header.match?(REGEXP_AUTHORIZATION_ENDPOINT_REL_PATTERN) }
|
51
|
+
|
52
|
+
return unless authorization_endpoint_header
|
53
|
+
|
54
|
+
endpoint_match_data = authorization_endpoint_header.match(REGEXP_TARGET_URI_PATTERN)
|
55
|
+
|
56
|
+
return endpoint_match_data[1] if endpoint_match_data
|
57
|
+
end
|
58
|
+
|
59
|
+
def endpoint_from_http_request
|
60
|
+
@endpoint_from_http_request ||= endpoint_from_headers || endpoint_from_body || nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module AuthorizationEndpoint
|
2
|
+
class Error < StandardError; end
|
3
|
+
|
4
|
+
class ArgumentError < Error; end
|
5
|
+
|
6
|
+
class ConnectionError < Error; end
|
7
|
+
|
8
|
+
class InvalidURIError < Error; end
|
9
|
+
|
10
|
+
class TimeoutError < Error; end
|
11
|
+
|
12
|
+
class TooManyRedirectsError < Error; end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AuthorizationEndpoint
|
2
|
+
class Response
|
3
|
+
HTTP_HEADERS_OPTS = {
|
4
|
+
accept: '*/*',
|
5
|
+
user_agent: 'Authorization Endpoint Discovery (https://rubygems.org/gems/authorization-endpoint)'
|
6
|
+
}.freeze
|
7
|
+
|
8
|
+
def initialize(uri)
|
9
|
+
raise ArgumentError, "uri must be an Addressable::URI (given #{uri.class.name})" unless uri.is_a?(Addressable::URI)
|
10
|
+
|
11
|
+
@uri = uri
|
12
|
+
end
|
13
|
+
|
14
|
+
def response
|
15
|
+
@response ||= HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout(
|
16
|
+
connect: 10,
|
17
|
+
read: 10
|
18
|
+
).get(@uri)
|
19
|
+
rescue HTTP::ConnectionError => error
|
20
|
+
raise ConnectionError, error
|
21
|
+
rescue HTTP::TimeoutError => error
|
22
|
+
raise TimeoutError, error
|
23
|
+
rescue HTTP::Redirector::TooManyRedirectsError => error
|
24
|
+
raise TooManyRedirectsError, error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,268 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: authorization-endpoint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Garber
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.16.2
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.16'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.16.2
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '12.3'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 12.3.1
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '12.3'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 12.3.1
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '3.7'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '3.7'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rubocop
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.58.1
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.58.1
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rubocop-rspec
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '1.27'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '1.27'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: simplecov
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.16.1
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 0.16.1
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: simplecov-console
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 0.4.2
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 0.4.2
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: webmock
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '3.4'
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 3.4.2
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '3.4'
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 3.4.2
|
143
|
+
- !ruby/object:Gem::Dependency
|
144
|
+
name: absolutely
|
145
|
+
requirement: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - "~>"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '1.1'
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - "~>"
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '1.1'
|
157
|
+
- !ruby/object:Gem::Dependency
|
158
|
+
name: addressable
|
159
|
+
requirement: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - "~>"
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '2.5'
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 2.5.2
|
167
|
+
type: :runtime
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '2.5'
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: 2.5.2
|
177
|
+
- !ruby/object:Gem::Dependency
|
178
|
+
name: http
|
179
|
+
requirement: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - "~>"
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '3.3'
|
184
|
+
type: :runtime
|
185
|
+
prerelease: false
|
186
|
+
version_requirements: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - "~>"
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '3.3'
|
191
|
+
- !ruby/object:Gem::Dependency
|
192
|
+
name: nokogiri
|
193
|
+
requirement: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - "~>"
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '1.8'
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: 1.8.4
|
201
|
+
type: :runtime
|
202
|
+
prerelease: false
|
203
|
+
version_requirements: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - "~>"
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '1.8'
|
208
|
+
- - ">="
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: 1.8.4
|
211
|
+
description: Discover a URL’s authorization endpoint for use with Micropub and IndieAuth
|
212
|
+
clients.
|
213
|
+
email:
|
214
|
+
- jason@sixtwothree.org
|
215
|
+
executables: []
|
216
|
+
extensions: []
|
217
|
+
extra_rdoc_files: []
|
218
|
+
files:
|
219
|
+
- ".editorconfig"
|
220
|
+
- ".gitignore"
|
221
|
+
- ".rspec"
|
222
|
+
- ".rubocop"
|
223
|
+
- ".rubocop.yml"
|
224
|
+
- ".ruby-version"
|
225
|
+
- ".simplecov"
|
226
|
+
- ".travis.yml"
|
227
|
+
- CHANGELOG.md
|
228
|
+
- CONTRIBUTING.md
|
229
|
+
- Gemfile
|
230
|
+
- LICENSE
|
231
|
+
- README.md
|
232
|
+
- Rakefile
|
233
|
+
- authorization-endpoint.gemspec
|
234
|
+
- lib/authorization_endpoint.rb
|
235
|
+
- lib/authorization_endpoint/client.rb
|
236
|
+
- lib/authorization_endpoint/discover.rb
|
237
|
+
- lib/authorization_endpoint/error.rb
|
238
|
+
- lib/authorization_endpoint/response.rb
|
239
|
+
- lib/authorization_endpoint/version.rb
|
240
|
+
homepage: https://github.com/jgarber623/authorization-endpoint-ruby
|
241
|
+
licenses:
|
242
|
+
- MIT
|
243
|
+
metadata: {}
|
244
|
+
post_install_message:
|
245
|
+
rdoc_options: []
|
246
|
+
require_paths:
|
247
|
+
- lib
|
248
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
249
|
+
requirements:
|
250
|
+
- - ">="
|
251
|
+
- !ruby/object:Gem::Version
|
252
|
+
version: '2.4'
|
253
|
+
- - "<"
|
254
|
+
- !ruby/object:Gem::Version
|
255
|
+
version: '2.6'
|
256
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
|
+
requirements:
|
258
|
+
- - ">="
|
259
|
+
- !ruby/object:Gem::Version
|
260
|
+
version: '0'
|
261
|
+
requirements: []
|
262
|
+
rubyforge_project:
|
263
|
+
rubygems_version: 2.6.14.1
|
264
|
+
signing_key:
|
265
|
+
specification_version: 4
|
266
|
+
summary: Discover a URL’s authorization endpoint for use with Micropub and IndieAuth
|
267
|
+
clients.
|
268
|
+
test_files: []
|