diff --git a/README.md b/README.md index 2bcbd84..3f645e4 100644 --- a/README.md +++ b/README.md @@ -4,28 +4,30 @@ This SDK allows a web developer to quickly add Duo's interactive, self-service, What's included: -* `duo_universal` - The Golang Duo SDK for interacting with the Duo Universal Prompt -* `main.go` - An example Go application with Duo integrated +* `duouniversal` - The Golang Duo SDK for interacting with the Duo Universal Prompt +* `example` - An example Go application with Duo integrated -## Getting started - -Go into `duo_universal/` and install the `duouniversal` package: +## Getting Started +To use the SDK in your existing development environment, install it using Go Modules ``` -go build +go mod init example +go get github.com/duosecurity/duo_universal_golang/duouniversal ``` +Once it's installed, see our developer documentation at https://duo.com/docs/duoweb and `example/main.go` in this repo for guidance on integrating Duo 2FA into your web application. +See https://github.com/duosecurity/duo_python/pull/57 for a step-by-step example of migrating an existing WebSDK2 integration to the Universal SDK. ## Contribute To contribute, fork this repo and make a pull request with your changes when they are ready. Install the SDK from source: ``` -cd duo_universal/ +cd duouniversal/ go build ``` ## Tests ``` -cd duo_universal/ +cd duouniversal/ go test ``` @@ -33,32 +35,4 @@ go test To run formatter ``` go fmt -``` - -## Demo -### Setup -Change to the "duo_universal" directory -``` -cd duo_universal -``` - -Install the `duouniversal` package -``` -go build -``` - -Then, create a `Web SDK` application in the Duo Admin Panel. See https://duo.com/docs/protecting-applications for more details. - -### Using the App - -1. Copy the Client ID, Client Secret, and API Hostname values for your `Web SDK` application into the `duo_config.json` file. -1. Change back to the root directory - ``` - cd .. - ``` -1. Start the app. - ``` - go run main.go - ``` -1. Navigate to http://localhost:8080. -1. Log in with the user you would like to enroll in Duo or with an already enrolled user (any password will work). +``` \ No newline at end of file diff --git a/duo_universal/client.go b/duouniversal/client.go similarity index 100% rename from duo_universal/client.go rename to duouniversal/client.go diff --git a/duo_universal/client_test.go b/duouniversal/client_test.go similarity index 100% rename from duo_universal/client_test.go rename to duouniversal/client_test.go diff --git a/duo_universal/duo_jwt.go b/duouniversal/duo_jwt.go similarity index 100% rename from duo_universal/duo_jwt.go rename to duouniversal/duo_jwt.go diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..b638005 --- /dev/null +++ b/example/README.md @@ -0,0 +1,36 @@ +# Duo Universal Golang SDK Demo + +A simple Go web application that serves a logon page integrated with Duo 2FA. + +## Setup +Change to the "example" directory +``` +cd example +``` + +Install the demo requirements: +``` +go mod tidy +``` + +Then, create a `Web SDK` application in the Duo Admin Panel. See https://duo.com/docs/protecting-applications for more details. + +## Using the App + +1. Copy the Client ID, Client Secret, and API Hostname values for your `Web SDK` application into the `duo_config.json` file. +1. Start the app. + ``` + go run main.go + ``` +1. Navigate to http://localhost:8080. +1. Log in with the user you would like to enroll in Duo or with an already enrolled user (any password will work). + +## (Optional) Run the demo using docker + +A dockerfile is included to easily run the demo app with a known working Go configuration. + +1. Copy the Client ID, Client Secret, and API Hostname values for your `Web SDK` application into the `duo_config.json` file. +1. Build the docker image: `docker build -t duo_golang_example .` +1. Run the docker container `docker run -p 8080:8080 duo_golang_example` +1. Navigate to http://localhost:8080. +1. Log in with the user you would like to enroll in Duo or with an already enrolled user (any password will work). \ No newline at end of file diff --git a/example/dockerfile b/example/dockerfile new file mode 100644 index 0000000..b3e71ce --- /dev/null +++ b/example/dockerfile @@ -0,0 +1,9 @@ +FROM golang:latest +EXPOSE 8080 +WORKDIR /go/src/app +ADD . . + +RUN go mod tidy + +WORKDIR /go/src/app/example +ENTRYPOINT ["go", "run", "main.go"] \ No newline at end of file diff --git a/duo_config.json b/example/duo_config.json similarity index 100% rename from duo_config.json rename to example/duo_config.json diff --git a/main.go b/example/main.go similarity index 98% rename from main.go rename to example/main.go index a2e00b1..3cff0ee 100644 --- a/main.go +++ b/example/main.go @@ -10,7 +10,7 @@ import ( "path" "strings" - duouniversal "./duo_universal" + "github.com/duosecurity/duo_universal_golang/duouniversal" ) const duoUnavailable = "Duo unavailable" diff --git a/static/images/logo.png b/example/static/images/logo.png similarity index 100% rename from static/images/logo.png rename to example/static/images/logo.png diff --git a/static/style.css b/example/static/style.css similarity index 100% rename from static/style.css rename to example/static/style.css diff --git a/templates/login.html b/example/templates/login.html similarity index 100% rename from templates/login.html rename to example/templates/login.html diff --git a/templates/success.html b/example/templates/success.html similarity index 100% rename from templates/success.html rename to example/templates/success.html diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1609407 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/duosecurity/duo_universal_golang + +go 1.16 + +require github.com/lestrrat-go/jwx v1.2.4