diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..890d932db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang + +WORKDIR /go/src/github.com/bitly/oauth2_proxy +ADD https://github.com/twhtanghk/oauth2_proxy/archive/master.tar.gz /tmp +RUN tar --strip-components=1 -xzf /tmp/master.tar.gz && \ + rm /tmp/master.tar.gz && \ + go get && \ + go build -o oauth2_proxy +EXPOSE 4180 + +ENTRYPOINT ./entrypoint.sh diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..2446bbfb1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: '2' +services: + oauth2_proxy: + image: twhtanghk/oauth2_proxy + container_name: oauth2_proxy + ports: + - 4180 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 000000000..af0e25f3a --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +./oauth2_proxy -config=/opt/oauth2-proxy/etc/config diff --git a/providers/mob.go b/providers/mob.go new file mode 100644 index 000000000..e9ce5f6d7 --- /dev/null +++ b/providers/mob.go @@ -0,0 +1,61 @@ +package providers + +import ( + "log" + "fmt" + "net/http" + "net/url" + + "github.com/bitly/oauth2_proxy/api" +) + +type MobProvider struct { + *ProviderData +} + +func NewMobProvider(p *ProviderData) *MobProvider { + p.ProviderName = "mob" + if p.LoginURL == nil || p.LoginURL.String() == "" { + p.LoginURL = &url.URL{ + Scheme: "https", + Host: "mob.myvnc.com", + Path: "/org/oauth2/authorize/", + } + } + if p.RedeemURL == nil || p.RedeemURL.String() == "" { + p.RedeemURL = &url.URL{ + Scheme: "https", + Host: "mob.myvnc.com", + Path: "/org/oauth2/token/", + } + } + if p.ValidateURL == nil || p.ValidateURL.String() == "" { + p.ValidateURL = &url.URL{ + Scheme: "https", + Host: "mob.myvnc.com", + Path: "/org/oauth2/verify/", + } + } + if p.Scope == "" { + p.Scope = "https://mob.myvnc.com/org/users" + } + return &MobProvider{ProviderData: p} +} + +func (p *MobProvider) GetEmailAddress(s *SessionState) (string, error) { + + req, err := http.NewRequest("GET", p.ValidateURL.String(), nil) + req.Header = make(http.Header) + req.Header.Set("Accept", "application/json") + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", s.AccessToken)) + if err != nil { + log.Printf("failed building request %s", err) + return "", err + } + json, err := api.Request(req) + if err != nil { + log.Printf("failed making request %s", err) + return "", err + } + return json.Get("user").Get("email").String() +} diff --git a/providers/providers.go b/providers/providers.go index fb2e5fc51..6fcba0240 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -30,6 +30,8 @@ func New(provider string, p *ProviderData) Provider { return NewAzureProvider(p) case "gitlab": return NewGitLabProvider(p) + case "mob": + return NewMobProvider(p) default: return NewGoogleProvider(p) }