An easy Sinatra extension for adding Webfinger support to your domain.
It's a way to attach information to your email address.
Take an email address, and ask its domain about it using HTTPS. For example, information about eric@konklone.com is available in JSON at:
https://konklone.com/.well-known/webfinger?resource=acct:eric@konklone.com
See webfinger.net, Paul E. Jones' description, or Webfinger's official standard at RFC 7033 for more information.
sinatra-webfinger is a small Sinatra extension optimized for single users, where you own your domain name, and you want to attach information to your email address.
Install it:
gem install sinatra-webfingerRequire it in your app:
require 'sinatra/webfinger'If you're using the modular style of Sinatra app, by subclassing Sinatra::Base, make sure to register the extension inside your class:
class MyApp < Sinatra::Base
register Sinatra::Webfinger
# ...rest of your app ...
endConfigure sinatra-webfinger by passing the webfinger method a hash where each key is an email address you want to attach details for. The value for each email address is another hash containing name/value pairs of data.
For each field, if its value is a URI beginning with http or https, it will be added to the Webfinger links array, where the field will be the rel and the value will be the href.
Otherwise, the field will be added to the Webfinger properties object, by that key and value.
For example:
webfinger "eric@konklone.com" => {
name: "Eric Mill",
website: "https://konklone.com"
}This will add a GET endpoint at /.well-known/webfinger?resource=acct:eric@konklone.com that produces:
{
"subject": "eric@konklone.com",
"properties": {
"http://schema.org/name": "Eric Mill"
},
"links": [
{
"rel": "http://webfinger.net/rel/profile-page",
"href": "https://konklone.com"
}
]
}In Webfinger, fields are URIs, but you can use common short strings and sinatra-webfinger will convert those to the current best practice URIs for you.
These URIs are defined in urns.yml. Please contribute to it!
It may be easiest to serialize your Webfinger configuration in YAML, then load it into Ruby and pass it to the webfinger method.
An example YAML file for the above example would be:
eric@konklone.com:
name: Eric Mill
website: https://konklone.comIf you saved that to webfinger.yml, you might configure your application using:
webfinger YAML.load_file('webfinger.yml')The Content-Type of the response will be application/jrd+json, and CORS will be enabled (Access-Control-Allow-Origin will be *).
A 400 will be returned if:
- There is no
resourceparameter provided in the query string. - There's any sort of Exception while parsing the
resourceURI.
A 404 will be returned if:
- A URI scheme other than
acctis submitted. - A
resourceis submitted for anacctthat isn't listed in the configuration.
A 500 will be returned if:
Sinatra::Webfinger.confighas not been set to anything.- There is any unplanned Exception.
This project is published under the MIT License.