Skip to main content
Homepage
Explore
Search or go to…
/
Sign in
Explore
Primary navigation
Project
C
cashier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Collapse sidebar
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Lyda
cashier
Commits
76fc7c9f
Commit
76fc7c9f
authored
Jul 31, 2018
by
Kevin Lyda
Browse files
Options
Downloads
Patches
Plain Diff
Provide a way to offer chunked tokens.
parent
6c306e58
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/cashier/main.go
+9
-3
9 additions, 3 deletions
cmd/cashier/main.go
server/web.go
+25
-0
25 additions, 0 deletions
server/web.go
with
34 additions
and
3 deletions
cmd/cashier/main.go
+
9
−
3
View file @
76fc7c9f
...
@@ -2,12 +2,14 @@ package main
...
@@ -2,12 +2,14 @@ package main
import
(
import
(
"bufio"
"bufio"
"bytes"
"fmt"
"fmt"
"log"
"log"
"net"
"net"
"os"
"os"
"os/user"
"os/user"
"path"
"path"
"strings"
"time"
"time"
"github.com/nsheridan/cashier/client"
"github.com/nsheridan/cashier/client"
...
@@ -49,12 +51,16 @@ func main() {
...
@@ -49,12 +51,16 @@ func main() {
}
}
fmt
.
Print
(
"Enter token: "
)
fmt
.
Print
(
"Enter token: "
)
var
token
string
scanner
:=
bufio
.
NewScanner
(
os
.
Stdin
)
fmt
.
Scanln
(
&
token
)
var
buffer
bytes
.
Buffer
for
scanner
.
Scan
();
strings
.
HasSuffix
(
scanner
.
Text
(),
"+++"
);
scanner
.
Scan
()
{
buffer
.
WriteString
(
scanner
.
Text
()[
:
len
(
scanner
.
Text
())
-
4
])
}
buffer
.
WriteString
(
scanner
.
Text
())
token
:=
buffer
.
String
()
var
message
string
var
message
string
fmt
.
Print
(
"Enter message: "
)
fmt
.
Print
(
"Enter message: "
)
scanner
:=
bufio
.
NewScanner
(
os
.
Stdin
)
if
scanner
.
Scan
()
{
if
scanner
.
Scan
()
{
message
=
scanner
.
Text
()
message
=
scanner
.
Text
()
}
}
...
...
...
...
This diff is collapsed.
Click to expand it.
server/web.go
+
25
−
0
View file @
76fc7c9f
package
server
package
server
import
(
import
(
"bytes"
"crypto/rand"
"crypto/rand"
"encoding/hex"
"encoding/hex"
"encoding/json"
"encoding/json"
...
@@ -181,6 +182,29 @@ func callbackHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int
...
@@ -181,6 +182,29 @@ func callbackHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int
return
http
.
StatusFound
,
nil
return
http
.
StatusFound
,
nil
}
}
func
chunkString
(
s
string
,
chunkSize
int
)
string
{
if
len
(
s
)
<=
chunkSize
{
return
s
}
var
buffer
bytes
.
Buffer
runes
:=
[]
rune
(
s
)
for
i
:=
0
;
i
<
len
(
runes
);
i
+=
chunkSize
{
end
:=
i
+
chunkSize
if
end
>
len
(
runes
)
{
end
=
len
(
runes
)
}
buffer
.
WriteString
(
string
(
runes
[
i
:
end
]))
buffer
.
WriteString
(
"+++
\n
"
)
}
chunks
:=
buffer
.
String
()
if
len
(
chunks
)
>
0
{
chunks
=
chunks
[
:
len
(
chunks
)
-
4
]
}
return
chunks
}
// rootHandler starts the auth process. If the client is authenticated it renders the token to the user.
// rootHandler starts the auth process. If the client is authenticated it renders the token to the user.
func
rootHandler
(
a
*
appContext
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
func
rootHandler
(
a
*
appContext
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
if
!
a
.
isLoggedIn
(
w
,
r
)
{
if
!
a
.
isLoggedIn
(
w
,
r
)
{
...
@@ -190,6 +214,7 @@ func rootHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int, er
...
@@ -190,6 +214,7 @@ func rootHandler(a *appContext, w http.ResponseWriter, r *http.Request) (int, er
page
:=
struct
{
page
:=
struct
{
Token
string
Token
string
}{
tok
.
AccessToken
}
}{
tok
.
AccessToken
}
page
.
Token
=
chunkString
(
page
.
Token
,
250
)
tmpl
:=
template
.
Must
(
template
.
New
(
"token.html"
)
.
Parse
(
templates
.
Token
))
tmpl
:=
template
.
Must
(
template
.
New
(
"token.html"
)
.
Parse
(
templates
.
Token
))
tmpl
.
Execute
(
w
,
page
)
tmpl
.
Execute
(
w
,
page
)
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment