Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Patch to add provider for mob.myvnc.com #286

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '2'
services:
oauth2_proxy:
image: twhtanghk/oauth2_proxy
container_name: oauth2_proxy
ports:
- 4180
3 changes: 3 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

./oauth2_proxy -config=/opt/oauth2-proxy/etc/config
61 changes: 61 additions & 0 deletions providers/mob.go
Original file line number Diff line number Diff line change
@@ -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()
}
2 changes: 2 additions & 0 deletions providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down