integration

package
v0.60.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

integration provides a server example for integration tests actual tests are carried out in `example_test` in the `examples/` folder

Index

Constants

View Source
const CookieName = "lnurlauth-token"

the cookie name stored int he users browser

Variables

View Source
var HomeTpl = template.Must(template.New("home").Parse(`
<!DOCTYPE html>
<html lang="en">
<body>
	{{ if . }}
		<p> You are authenticated. To logout, go <a href="/logout"> here </a>
	{{ else }}
		<p> You are not authenticated. To login, go <a href="/login"> here </a>
	{{ end }}
</body>
</html>
`))

the home page template

View Source
var LoginPage = template.Must(template.New("login").Parse(`
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Login with lnurl-auth</title>
	<style>
		html, body {
			width: 100%;
			height: 100%;
			color: #fff;
			font-family: sans;
			background: #222;
			margin: 0;
		}
		h1 {
			margin: 0 0 .5rem 0;
		}
		p {
			font-weight: 100;
			line-height: 150%;
			margin: 0 0 1rem 0;
		}
		#content {
			display: flex;
			height: 100%;
			text-align: center;
		}
		.wrap {
			width: 80%;
			max-width: 24rem;
			align-self: center;
			margin: 0 auto;
		}
		#qrcode {
			display: block;
			width: 16rem;
			height: 16rem;
			margin: 0 auto;
		}
		#qrcode img {
			display: block;
			width: 100%;
		}
		.button {
			cursor: pointer;
			color: #fff;
			font-size: 1.1rem;
			line-height: 1.8rem;
			background: #c95b59;
			border: none;
			outline: none;
			border-radius: .4rem;
			opacity: .7;
			padding: .4rem .8rem;
		}
		a.button,
		a.button:hover {
			text-decoration: none;
		}
		.button:hover {
			opacity: 1;
		}
		#buttons {
			display: block;
			margin-top: 1rem;
		}
	</style>
	<meta http-equiv="refresh" content="8">
</head>
<body>

	<div id="content">
		<div class="wrap">
			<h1>Login with lnurl-auth</h1>
			<p>Scan the QR code with an app that supports lnurl-auth</p>
			<a id="qrcode" href="lightning:{{.Encoded}}"><img src="{{.DataUri}}"></a>
			<div id="buttons">
				{{if .LogoutUrl }}
					<a href="{{.LogoutUrl}}" class="button">Cancel</a>
				{{end}}
			</div>
		</div>
	</div>

</body>
</html>
`))

the login page template

Functions

func GenerateServer

func GenerateServer() http.Server

generate a server object

func ParseUrl

func ParseUrl(rawUrl string) lnurlHelper.LNURLAuthParams

parses a url into auth params

func SignCallbackUrl

func SignCallbackUrl(rawCallbackUri string) (res string, err error)

sign a callback url with a pre-defined private key

Types

type AuthStatus

type AuthStatus struct {
	// Whether or not the user is authenticated
	IsAuthenticated bool `json:"is_authenticated"`
}

AuthStatus returns the current authentication status of the user.

type CallbackStatus

type CallbackStatus struct {
	Ok bool `json:"ok"`
}

CallbackStatus returns whether or not a callback was successful to a ln wallet

type LoginPageData

type LoginPageData struct {
	// encoded lnurl string
	Encoded string
	// data uri string
	DataUri template.URL
	// logout url
	LogoutUrl string
}

data passed to the login page

type SignedMessage

type SignedMessage struct {
	// (hex encoded 32 bytes of challenge) which is going to be signed by user's linkingPrivKey.
	K1 string
	// signature of message using secp256k1 on the linkingPrivKey
	Sig string
	//  the linking key https://git.io/JqT7T
	Key string
}

a signed k1

type TestRunner

type TestRunner struct {
	// http client to use for tests
	Client *http.Client
	// testing object to report errors to
	Tester *testing.T
	// base url to test against
	Url string
}

helper methods

func (TestRunner) Get

func (t TestRunner) Get(route string) *http.Response

get a given route with a bypass header for local tunnels

func (TestRunner) GetAuthStatus

func (t TestRunner) GetAuthStatus() AuthStatus

retreive the users authentication status

func (TestRunner) GetLoginPage

func (t TestRunner) GetLoginPage() (lnurl string, didRedirect bool)

returns lnurl if availalable, and wether or not a recirect was attempted

Jump to

Keyboard shortcuts

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