Skip to content

Commit

Permalink
Reorganize code to improve importing
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyparker committed Jul 20, 2021
1 parent 130f61f commit a268cb8
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 38 deletions.
48 changes: 11 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,35 @@ 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
```

## Format
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).
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -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).
9 changes: 9 additions & 0 deletions example/dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
File renamed without changes.
2 changes: 1 addition & 1 deletion main.go → example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"path"
"strings"

duouniversal "./duo_universal"
"github.com/duosecurity/duo_universal_golang/duouniversal"
)

const duoUnavailable = "Duo unavailable"
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/duosecurity/duo_universal_golang

go 1.16

require github.com/lestrrat-go/jwx v1.2.4

0 comments on commit a268cb8

Please sign in to comment.