webfinger

package module
v0.0.0-...-c529bc7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2013 License: MIT Imports: 9 Imported by: 1

README

Go-Webfinger

Go client for the Webfinger protocol

Build Status

Go-Webfinger is a Go client for the Webfinger protocol.

*It is a work in progress, the API is not frozen. We're trying to catchup with the last draft of the protocol: http://tools.ietf.org/html/draft-ietf-appsawg-webfinger-14 and to support the http://webfist.org *

Install

This package is "go-gettable", just do:

go get github.com/ant0ine/go-webfinger

Example

package main

import (
        "fmt"
        "github.com/ant0ine/go-webfinger"
        "os"
)

func main() {
        email := os.Args[1]

        client := webfinger.NewClient(nil)

        resource, err := webfinger.MakeResource(email)
        if err != nil {
                panic(err)
        }

        jrd, err := client.GetJRD(resource)
        if err != nil {
                fmt.Println(err)
                return
        }

        fmt.Printf("JRD: %+v", jrd)
}

Documentation

Author

Contributors

  • Thanks Will Norris for the major update to support draft-14, and the GAE compat!

MIT License

Documentation

Overview

Package webfinger provides a simple client implementation of the WebFinger protocol.

It is a work in progress, the API is not frozen. We're trying to catchup with the last draft of the protocol: http://tools.ietf.org/html/draft-ietf-appsawg-webfinger-14 and to support the http://webfist.org

Example:

package main

import (
        "fmt"
        "github.com/ant0ine/go-webfinger"
        "os"
)

func main() {
        email := os.Args[1]

        client := webfinger.NewClient(nil)

        resource, err := webfinger.MakeResource(email)
        if err != nil {
                panic(err)
        }

        jrd, err := client.GetJRD(resource)
        if err != nil {
                fmt.Println(err)
                return
        }

        fmt.Printf("JRD: %+v", jrd)
}

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = &Client{
	client:        http.DefaultClient,
	WebFistServer: webFistDefaultServer,
}

DefaultClient is the default Client and is used by Lookup.

Functions

func Lookup

func Lookup(identifier string, rels []string) (*jrd.JRD, error)

Lookup returns the JRD for the specified identifier.

Lookup is a wrapper around DefaultClient.Lookup.

Types

type Client

type Client struct {

	// WebFistServer is the host used for issuing WebFist queries when standard
	// WebFinger lookup fails.  If set to the empty string, queries will not fall
	// back to the WebFist protocol.
	WebFistServer string

	// Allow the use of HTTP endoints for lookups.  The WebFinger spec requires
	// all lookups be performed over HTTPS, so this should only ever be enabled
	// for development.
	AllowHTTP bool
	// contains filtered or unexported fields
}

A Client is a WebFinger client.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new WebFinger Client. If a nil http.Client is provied, http.DefaultClient will be used. New Clients will use the default WebFist host if WebFinger lookup fails.

func (*Client) LegacyGetJRD

func (self *Client) LegacyGetJRD(resource *Resource, allow_insecure bool) (*jrd.JRD, error)

LegacyGetJRD gets the JRD data for this resource. Implement the original WebFinger API, ie: first fetch the Host metadata, find the LRDD link, fetch the resource data and convert the XRD in JRD if necessary.

func (*Client) LegacyGetResourceJRDTemplateURL

func (self *Client) LegacyGetResourceJRDTemplateURL(domain string, allow_insecure bool) (string, error)

LegacyGetResourceJRDTemplateURL gets the host meta JRD data for the specified domain, and returns the LRDD resource JRD template URL. It tries all the urls returned by client.LegacyHostJRDURLs.

func (*Client) LegacyHostJRDURLs

func (self *Client) LegacyHostJRDURLs(domain string, allow_insecure bool) []string

LegacyHostJRDURLs builds a series of well known host JRD URLs from the domain.

func (*Client) Lookup

func (c *Client) Lookup(identifier string, rels []string) (*jrd.JRD, error)

Lookup returns the JRD for the specified identifier. If provided, only the specified rel values will be requested, though WebFinger servers are not obligated to respect that request.

func (*Client) LookupInsecure

func (c *Client) LookupInsecure(identifier string, rels []string) (*jrd.JRD, error)

LookupInsecure returns the JRD for the specified identifier. If provided, only the specified rel values will be requested, though WebFinger servers are not obligated to respect that request. allows http via fallback

func (*Client) LookupResource

func (c *Client) LookupResource(resource *Resource, rels []string, allow_insecure bool) (*jrd.JRD, error)

LookupResource returns the JRD for the specified Resource. If provided, only the specified rel values will be requested, though WebFinger servers are not obligated to respect that request.

type Resource

type Resource url.URL

Resource is a resource for which a WebFinger query can be issued.

func Parse

func Parse(rawurl string) (*Resource, error)

Parse parses rawurl into a WebFinger Resource. The rawurl should be an absolute URL, or an email-like identifier (e.g. "bob@example.com").

func (*Resource) AsURIString

func (self *Resource) AsURIString() string

AsURIString returns the resource as an URI string (eg: acct:user@domain).

func (*Resource) JRDURL

func (r *Resource) JRDURL(host string, rels []string, use_http bool) *url.URL

JRDURL returns the WebFinger query URL at the specified host for this resource. If host is an empty string, the default host for the resource will be used, as returned from WebFingerHost().

func (*Resource) String

func (r *Resource) String() string

String reassembles the Resource into a valid URL string.

func (*Resource) WebFingerHost

func (r *Resource) WebFingerHost() string

WebFingerHost returns the default host for issuing WebFinger queries for this resource. For Resource URLs with a host component, that value is used. For URLs that do not have a host component, the host is determined by other mains if possible (for example, the domain in the addr-spec of a mailto URL). If the host cannot be determined from the URL, this value will be an empty string.

Directories

Path Synopsis
examples
cmdline
TODO * improve JRD output * do stuff with the JRD
TODO * improve JRD output * do stuff with the JRD
simple
Minimal example, used in the README
Minimal example, used in the README
Package jrd provides a simple JRD parser.
Package jrd provides a simple JRD parser.
Package xrd provides a simple XRD parser.
Package xrd provides a simple XRD parser.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL