1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/lib/controller/rpc"
14 "git.arvados.org/arvados.git/sdk/go/arvados"
15 "git.arvados.org/arvados.git/sdk/go/ctxlog"
16 "github.com/sirupsen/logrus"
19 type testLoginController struct {
20 Cluster *arvados.Cluster
24 func (ctrl *testLoginController) Logout(ctx context.Context, opts arvados.LogoutOptions) (arvados.LogoutResponse, error) {
25 return logout(ctx, ctrl.Cluster, opts)
28 func (ctrl *testLoginController) Login(ctx context.Context, opts arvados.LoginOptions) (arvados.LoginResponse, error) {
29 tmpl, err := template.New("form").Parse(loginform)
31 return arvados.LoginResponse{}, err
34 err = tmpl.Execute(&buf, opts)
36 return arvados.LoginResponse{}, err
38 return arvados.LoginResponse{HTML: buf}, nil
41 func (ctrl *testLoginController) UserAuthenticate(ctx context.Context, opts arvados.UserAuthenticateOptions) (arvados.APIClientAuthorization, error) {
42 for username, user := range ctrl.Cluster.Login.Test.Users {
43 if (opts.Username == username || opts.Username == user.Email) && opts.Password == user.Password {
44 ctxlog.FromContext(ctx).WithFields(logrus.Fields{
47 }).Debug("test authentication succeeded")
48 return ctrl.Parent.CreateAPIClientAuthorization(ctx, ctrl.Cluster.SystemRootToken, rpc.UserSessionAuthInfo{
54 return arvados.APIClientAuthorization{}, fmt.Errorf("authentication failed for user %q with password len=%d", opts.Username, len(opts.Password))
60 <head><title>Arvados test login</title>
62 async function authenticate(event) {
63 event.preventDefault()
64 document.getElementById('error').innerHTML = ''
65 const resp = await fetch('/arvados/v1/users/authenticate', {
68 headers: {'Content-Type': 'application/json'},
69 body: JSON.stringify({
70 username: document.getElementById('username').value,
71 password: document.getElementById('password').value,
75 document.getElementById('error').innerHTML = '<p>Authentication failed.</p><p>The "test login" users are defined in Clusters.[ClusterID].Login.Test.Users section of config.yml</p><p>If you are using arvbox, use "arvbox adduser" to add users.</p>'
78 var redir = document.getElementById('return_to').value
79 if (redir.indexOf('?') > 0) {
84 const respj = await resp.json()
85 document.location = redir + "api_token=v2/" + respj.uuid + "/" + respj.api_token
90 <h3>Arvados test login</h3>
92 <input id="return_to" type="hidden" name="return_to" value="{{.ReturnTo}}">
93 username <input id="username" type="text" name="username" autofocus size=16>
94 password <input id="password" type="password" name="password" size=16>
95 <input type="submit" value="Log in">
101 document.getElementsByTagName('form')[0].onsubmit = authenticate