Skip to content

Commit 81661a5

Browse files
author
Alan Braithwaite
committed
providers: add okta
1 parent cddd2fc commit 81661a5

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Valid providers are :
3333
* [GitLab](#gitlab-auth-provider)
3434
* [LinkedIn](#linkedin-auth-provider)
3535
* [MyUSA](#myusa-auth-provider)
36+
* [Okta](#okta-auth-provider)
3637

3738
The provider can be selected using the `provider` configuration value.
3839

@@ -139,6 +140,11 @@ For adding an application to the Microsoft Azure AD follow [these steps to add a
139140

140141
Take note of your `TenantId` if applicable for your situation. The `TenantId` can be used to override the default `common` authorization server with a tenant specific server.
141142

143+
### Okta Auth Provider
144+
145+
[Okta](https://www.okta.com/) is a hosted SSO provider. You will need to set the `okta-domain` to your organization's Okta domain.
146+
147+
142148
## Email Authentication
143149

144150
To authorize by email domain use `--email-domain=yourcompany.com`. To authorize individual email addresses use `--authenticated-emails-file=/path/to/file` with one email per line. To authorize all email addresses use `--email-domain=*`.

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func main() {
4949
flagSet.Var(&googleGroups, "google-group", "restrict logins to members of this google group (may be given multiple times).")
5050
flagSet.String("google-admin-email", "", "the google admin to impersonate for api calls")
5151
flagSet.String("google-service-account-json", "", "the path to the service account json credentials")
52+
flagSet.String("okta-domain", "", "the full domain for which your organization's okta is configured (example.okta.com)")
5253
flagSet.String("client-id", "", "the OAuth Client ID: ie: \"123456.apps.googleusercontent.com\"")
5354
flagSet.String("client-secret", "", "the OAuth Client Secret")
5455
flagSet.String("authenticated-emails-file", "", "authenticate against emails via file (one per line)")

options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Options struct {
3535
GoogleGroups []string `flag:"google-group" cfg:"google_group"`
3636
GoogleAdminEmail string `flag:"google-admin-email" cfg:"google_admin_email"`
3737
GoogleServiceAccountJSON string `flag:"google-service-account-json" cfg:"google_service_account_json"`
38+
OktaDomain string `flag:"okta-domain" cfg:"okta_domain"`
3839
HtpasswdFile string `flag:"htpasswd-file" cfg:"htpasswd_file"`
3940
DisplayHtpasswdForm bool `flag:"display-htpasswd-form" cfg:"display_htpasswd_form"`
4041
CustomTemplatesDir string `flag:"custom-templates-dir" cfg:"custom_templates_dir"`
@@ -252,6 +253,8 @@ func parseProviderInfo(o *Options, msgs []string) []string {
252253
p.SetGroupRestriction(o.GoogleGroups, o.GoogleAdminEmail, file)
253254
}
254255
}
256+
case *providers.OktaProvider:
257+
p.SetOktaDomain(o.OktaDomain)
255258
}
256259
return msgs
257260
}

providers/okta.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package providers
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net/http"
7+
"net/url"
8+
9+
"github.com/bitly/oauth2_proxy/api"
10+
)
11+
12+
type OktaProvider struct {
13+
*ProviderData
14+
}
15+
16+
func (p *OktaProvider) SetOktaDomain(domain string) {
17+
if p.LoginURL == nil || p.LoginURL.String() == "" {
18+
p.LoginURL = &url.URL{
19+
Scheme: "https",
20+
Host: domain,
21+
Path: "/oauth2/v1/authorize",
22+
}
23+
}
24+
if p.RedeemURL == nil || p.RedeemURL.String() == "" {
25+
p.RedeemURL = &url.URL{
26+
Scheme: "https",
27+
Host: domain,
28+
Path: "/oauth2/v1/token",
29+
}
30+
}
31+
if p.ValidateURL == nil || p.ValidateURL.String() == "" {
32+
p.ValidateURL = &url.URL{
33+
Scheme: "https",
34+
Host: domain,
35+
Path: "/oauth2/v1/userinfo",
36+
}
37+
}
38+
}
39+
40+
func NewOktaProvider(p *ProviderData) *OktaProvider {
41+
p.ProviderName = "Okta"
42+
if p.Scope == "" {
43+
p.Scope = "openid profile email"
44+
}
45+
return &OktaProvider{ProviderData: p}
46+
}
47+
48+
func getOktaHeader(access_token string) http.Header {
49+
header := make(http.Header)
50+
header.Set("Authorization", fmt.Sprintf("Bearer %s", access_token))
51+
return header
52+
}
53+
54+
func (p *OktaProvider) GetEmailAddress(s *SessionState) (string, error) {
55+
56+
req, err := http.NewRequest("GET",
57+
p.ValidateURL.String(), nil)
58+
if err != nil {
59+
log.Printf("failed building request %s", err)
60+
return "", err
61+
}
62+
req.Header = getOktaHeader(s.AccessToken)
63+
json, err := api.Request(req)
64+
if err != nil {
65+
log.Printf("failed making request %s", err)
66+
return "", err
67+
}
68+
return json.Get("email").String()
69+
}

providers/providers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func New(provider string, p *ProviderData) Provider {
3030
return NewAzureProvider(p)
3131
case "gitlab":
3232
return NewGitLabProvider(p)
33+
case "okta":
34+
return NewOktaProvider(p)
3335
default:
3436
return NewGoogleProvider(p)
3537
}

0 commit comments

Comments
 (0)