Skip to content

Commit

Permalink
Adding session handling (#3)
Browse files Browse the repository at this point in the history
* Adding initial login for github with proper session handling

* Fixing logging to be clearer

* Adding initial sync for manager, updating schema for github flow to include a next url

* Moving session manager into its own package

* Adding registration with async cache

* Adding test case for session

* Updating storage interface order

* Updating v1Options to allow for next URL to be programmable

* Updating API to shut down manager and authentication providers

* Updating API to shut down manager and authentication providers

* Making it safe to shutdown the database even it if was started in an error

* Fixing panic

* Updating auth login endpoints to all be get requests

* Updating swagger for new github callback changes

* Adding logging to manager

* Theoretically working device code flow

* Fixing API so that it shuts down the Device provider

* Updating manager to create secret key and registration key if it does not already exist

* Updating manager because storage for registration will never return key not found error

* Adding better errors to manager

* Adding better errors to manager

* Updating device flow API to properly return errors for the polling rate

* Fixing deadlock in manager

* Fixing bug in device flow where lowercase strings could be returned

* Fixing bug in device flow where lowercase strings could be returned

* Adding better logging

* Adding logging for better debuggability

* Fixing bug where logger wasn't being propagated to db

* Adding better logging

* Making sure aes encryption returns a base64 encoded string and requires ones back

* Making sure aes encryption returns a base64 encoded string and requires ones back

* Moving ent package to internal folder

* Adding test case runner

* Making sure tls propagates in manager cookie setter

* starting to add api key and service key functionality

* Hooking up api key provider

* Cleaning up api key interfaces

* Adding api key validation code (#1)

* Adding Service Key Interface (#2)

* Fixing old api key code (removed option)

* Adding service key login

* Adding logged in and logout routes

* Adding logged in and logout routes

* Updating comments regarding service key session handling

* Updating generated code
  • Loading branch information
ShivanshVij authored Jan 9, 2023
1 parent cd5968a commit 704c144
Show file tree
Hide file tree
Showing 116 changed files with 11,330 additions and 14,444 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on:
pull_request:
branches:
- "*"

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.19"
check-latest: true
cache: true

- name: Test
run: go test -v ./...
46 changes: 46 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2023 Loophole Labs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package auth

const (
APIKeyPrefixString = "AK-"
ServiceKeyPrefixString = "SK-"
ServiceKeySessionPrefixString = "SS-"
)

var (
APIKeyPrefix = []byte(APIKeyPrefixString)
ServiceKeySessionPrefix = []byte(ServiceKeySessionPrefixString)
)

const (
SessionContextKey = "session"
APIKeyContextKey = "apikey"
ServiceKeySessionContextKey = "service"
UserContextKey = "user"
OrganizationContextKey = "organization"
)

type Kind string

const (
KindContextKey Kind = "kind"

KindSession Kind = "session"
KindAPIKey Kind = "api"
KindServiceKey Kind = "service"
)
98 changes: 20 additions & 78 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,115 +2,57 @@ module github.com/loopholelabs/auth

go 1.18

replace github.com/cli/oauth => github.com/loopholelabs/oauth v0.10.0

replace github.com/dexidp/dex => github.com/loopholelabs/dex v0.0.0-20221115010751-2d5dae79c41f

require (
entgo.io/ent v0.11.3
github.com/AppsFlyer/go-sundheit v0.5.0
github.com/cli/oauth v0.9.0
github.com/dexidp/dex v0.0.0-20221011121916-54c9e8231fb8
github.com/go-openapi/runtime v0.24.2
github.com/gofiber/fiber/v2 v2.39.0
entgo.io/ent v0.11.4
github.com/gofiber/fiber/v2 v2.40.1
github.com/google/uuid v1.3.0
github.com/joho/godotenv v1.4.0
github.com/grokify/go-pkce v0.2.0
github.com/lib/pq v1.10.7
github.com/mattn/go-sqlite3 v1.14.16
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.1
github.com/valyala/fasthttp v1.40.0
golang.org/x/crypto v0.1.0
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1
gopkg.in/square/go-jose.v2 v2.6.0
github.com/rs/zerolog v1.28.0
github.com/stretchr/testify v1.8.0
github.com/swaggo/swag v1.8.9
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167
golang.org/x/oauth2 v0.3.0
)

require (
ariga.io/atlas v0.7.2-0.20220927111110-867ee0cca56a // indirect
cloud.google.com/go/compute v1.10.0 // indirect
github.com/Azure/go-ntlmssp v0.0.0-20220621081337-cb9428e4ac1e // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
ariga.io/atlas v0.7.3-0.20221011160332-3ca609863edd // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/agext/levenshtein v1.2.1 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/beevik/etree v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cli/browser v1.0.0 // indirect
github.com/cli/safeexec v1.0.0 // indirect
github.com/coreos/go-oidc/v3 v3.4.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dexidp/dex/api/v2 v2.1.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
github.com/go-ldap/ldap/v3 v3.4.4 // indirect
github.com/go-openapi/analysis v0.21.2 // indirect
github.com/go-openapi/errors v0.20.2 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/loads v0.21.1 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/strfmt v0.21.2 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/go-openapi/validate v0.21.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
github.com/huandu/xstrings v1.3.1 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.15.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russellhaering/goxmldsig v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.41.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/zclconf/go-cty v1.8.0 // indirect
go.mongodb.org/mongo-driver v1.8.3 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/exp v0.0.0-20221004215720-b9f4876ce741 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/api v0.101.0 // indirect
golang.org/x/net v0.3.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221018160656-63c7b68cfc55 // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 704c144

Please sign in to comment.