-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dev6699/feat/auth
Add totp, basic auth check option
- Loading branch information
Showing
17 changed files
with
339 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
.PHONY: run | ||
run: | ||
go run cmd/rterm/main.go | ||
@go run cmd/rterm/main.go | ||
|
||
.PHONY: totp | ||
totp: | ||
@go run cmd/totp/main.go | ||
|
||
.PHONY: build | ||
build: | ||
CGO_ENABLED=0 go build -o rterm cmd/rterm/main.go | ||
@CGO_ENABLED=0 go build -o rterm cmd/rterm/main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package auth | ||
|
||
import "github.com/pquerna/otp/totp" | ||
|
||
type AuthCheck interface { | ||
Verify(code string) (bool, error) | ||
} | ||
|
||
func NewBasic(code string) AuthCheck { | ||
return authBasic{ | ||
code: code, | ||
} | ||
} | ||
|
||
type authBasic struct { | ||
code string | ||
} | ||
|
||
func (a authBasic) Verify(code string) (bool, error) { | ||
return code == a.code, nil | ||
} | ||
|
||
func NewTOTP(secret string) AuthCheck { | ||
return authTOTP{ | ||
secret: secret, | ||
} | ||
} | ||
|
||
type authTOTP struct { | ||
secret string | ||
} | ||
|
||
func (a authTOTP) Verify(code string) (bool, error) { | ||
return totp.Validate(code, a.secret), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"image" | ||
"log" | ||
|
||
"github.com/pquerna/otp/totp" | ||
) | ||
|
||
func main() { | ||
key, err := totp.Generate(totp.GenerateOpts{ | ||
AccountName: "dev6699", | ||
Issuer: "rterm", | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Println("Secret: ", key.Secret()) | ||
|
||
img, err := key.Image(45, 45) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("QR Code:") | ||
printQR(img) | ||
} | ||
|
||
func printQR(img image.Image) { | ||
bounds := img.Bounds() | ||
width := bounds.Max.X | ||
height := bounds.Max.Y | ||
|
||
for y := 0; y < height; y++ { | ||
for x := 0; x < width; x++ { | ||
color := img.At(x, y) | ||
r, g, b, _ := color.RGBA() | ||
grayscale := (r + g + b) / 3 | ||
if grayscale > 0x7FFF { | ||
fmt.Print(" ") | ||
} else { | ||
fmt.Print("██") | ||
} | ||
} | ||
fmt.Print("\n") | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI= | ||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= | ||
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= | ||
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= | ||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/pquerna/otp v1.4.0 h1:wZvl1TIVxKRThZIBiwOOHOGP/1+nZyWBil9Y2XNEDzg= | ||
github.com/pquerna/otp v1.4.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= | ||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.