Skip to content
This repository was archived by the owner on Oct 17, 2020. It is now read-only.
9 changes: 9 additions & 0 deletions backend/app/adapter/facebook/instrumentation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package facebook

import (
"github.com/short-d/short/backend/app/usecase/instrumentation"
)

func NewInstrumentationFactory() instrumentation.SSOInstrumentation {
return instrumentation.NewSSO("facebook")
}
2 changes: 2 additions & 0 deletions backend/app/adapter/facebook/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package facebook

import "github.com/short-d/short/backend/app/usecase/sso"

const ProviderName = "facebook"

// AccountLinker links user's Facebook account with Short account.
type AccountLinker sso.AccountLinker

Expand Down
9 changes: 9 additions & 0 deletions backend/app/adapter/github/instrumentation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package github

import (
"github.com/short-d/short/backend/app/usecase/instrumentation"
)

func NewInstrumentation() instrumentation.SSO {
return instrumentation.NewSSO("github")
}
2 changes: 2 additions & 0 deletions backend/app/adapter/github/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package github

import "github.com/short-d/short/backend/app/usecase/sso"

const ProviderName = "github"

// AccountLinker links user's Github account with Short account.
type AccountLinker sso.AccountLinker

Expand Down
9 changes: 9 additions & 0 deletions backend/app/adapter/google/instrumentation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package google

import (
"github.com/short-d/short/backend/app/usecase/instrumentation"
)

func NewInstrumentation() instrumentation.SSO {
return instrumentation.NewSSO("google")
}
2 changes: 2 additions & 0 deletions backend/app/adapter/google/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package google

import "github.com/short-d/short/backend/app/usecase/sso"

const ProviderName = "google"

// AccountLinker links user's Google account with Short account.
type AccountLinker sso.AccountLinker

Expand Down
25 changes: 25 additions & 0 deletions backend/app/adapter/request/instrumentationfactory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package request

import (
"github.com/short-d/app/fw/analytics"
"github.com/short-d/app/fw/logger"
"github.com/short-d/app/fw/metrics"
"github.com/short-d/app/fw/timer"
"github.com/short-d/short/backend/app/usecase/keygen"
)

type SSOInstrumentationFactory struct {
ssoProviderName string
keyGen keygen.KeyGenerator
logger logger.Logger
timer timer.Timer
metrics metrics.Metrics
analytics analytics.Analytics
client Client
}

// NewInstrumentationcFactory creates Instrumentation factory.
func NewSSOInstrumentationFactory(
provider string) SSOInstrumentationFactory {
return SSOInstrumentationFactory{}
}
4 changes: 4 additions & 0 deletions backend/app/adapter/routing/handle/sso_signin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handle

import (
"github.com/short-d/short/backend/app/adapter/request"
"net/http"
"net/url"

Expand All @@ -10,8 +11,10 @@ import (

// SSOSignIn redirects user to the sign in page.
func SSOSignIn(
instrumentationFactory request.InstrumentationFactory,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
instrumentationFactory request.InstrumentationFactory,
instrumentationFactory request.SSOInstrumentationFactory,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this a bit further, are we trying to compose an instrumentationFactory within an SSOInstrumentationFactory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ashakibp Nope. SSO sign in only depends on SSOInstrumentationFactory, which constructs instrumentation.SSO

singleSignOn sso.SingleSignOn,
webFrontendURL string,
provider string,
) router.Handle {
return func(w http.ResponseWriter, r *http.Request, params router.Params) {
token := getToken(params)
Expand All @@ -20,6 +23,7 @@ func SSOSignIn(
return
}
signInLink := singleSignOn.GetSignInLink()
//insert instrumentation
http.Redirect(w, r, signInLink, http.StatusSeeOther)
}
}
Expand Down
8 changes: 8 additions & 0 deletions backend/app/adapter/routing/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
// NewShort creates HTTP routing table.
func NewShort(
instrumentationFactory request.InstrumentationFactory,
ssoInstrumentationFactory request.SSOInstrumentationFactory,
webFrontendURL string,
timer timer.Timer,
shortLinkRetriever shortlink.Retriever,
Expand All @@ -41,8 +42,10 @@ func NewShort(
Method: "GET",
Path: "/oauth/github/sign-in",
Handle: handle.SSOSignIn(
instrumentationFactory,
sso.SingleSignOn(githubSSO),
webFrontendURL,
github.ProviderName,
),
},
{
Expand All @@ -57,8 +60,10 @@ func NewShort(
Method: "GET",
Path: "/oauth/facebook/sign-in",
Handle: handle.SSOSignIn(
instrumentationFactory,
sso.SingleSignOn(facebookSSO),
webFrontendURL,
facebook.ProviderName,
),
},
{
Expand All @@ -67,14 +72,17 @@ func NewShort(
Handle: handle.SSOSignInCallback(
sso.SingleSignOn(facebookSSO),
*frontendURL,
facebook.ProviderName,
),
},
{
Method: "GET",
Path: "/oauth/google/sign-in",
Handle: handle.SSOSignIn(
instrumentationFactory,
sso.SingleSignOn(googleSSO),
webFrontendURL,
google.ProviderName,
),
},
{
Expand Down
2 changes: 2 additions & 0 deletions backend/app/usecase/instrumentation/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func NewInstrumentation(
searchFailedCh := make(chan ctx.ExecutionContext)
madeFeatureDecisionCh := make(chan ctx.ExecutionContext)
trackCh := make(chan ctx.ExecutionContext)
ssoSignIn := make(chan ctx.ExecutionContext)

ins := &Instrumentation{
logger: logger,
Expand Down Expand Up @@ -210,6 +211,7 @@ func NewInstrumentation(
go func() { searchFailedCh <- c }()
go func() { madeFeatureDecisionCh <- c }()
go func() { trackCh <- c }()
go func() { ssoSignIn <- c }()
close(ctxCh)
}()
return *ins
Expand Down
54 changes: 54 additions & 0 deletions backend/app/usecase/instrumentation/sso.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package instrumentation

import (
"fmt"
"github.com/short-d/app/fw/analytics"
"github.com/short-d/app/fw/ctx"
"github.com/short-d/app/fw/logger"
"github.com/short-d/app/fw/metrics"
"github.com/short-d/app/fw/timer"
"github.com/short-d/short/backend/app/usecase/keygen"
)

type SSOInstrumentation struct {
event string
keyGen keygen.KeyGenerator
logger logger.Logger
timer timer.Timer
metrics metrics.Metrics
analytics analytics.Analytics
ssoSignIn chan ctx.ExecutionContext
}

func (i SSOInstrumentation) StartingSSO() {
}

func (i SSOInstrumentation) UserAlreadySignedIn() {

}

func (i SSOInstrumentation) RetrievingAuthToken() {

}

func (i SSOInstrumentation) SignInFailed() {

}

func (i SSOInstrumentation) SignInSucceeded() {

}

func (i SSOInstrumentation) VerifyingAuthToken(token string) {
i.logger.Info("Checking if auth token exists")
}

func (i SSOInstrumentation) RedirectingUserToSignInLink(signInLink string) {

}

func NewSSO(providerName string) SSOInstrumentation {
return SSOInstrumentation{
event: fmt.Sprintf("%s-SSO", providerName),
}
}
1 change: 0 additions & 1 deletion backend/app/usecase/sso/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sso

import (
"errors"

"github.com/short-d/short/backend/app/usecase/authenticator"
)

Expand Down
8 changes: 7 additions & 1 deletion backend/dep/provider/facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"github.com/short-d/app/fw/webreq"
"github.com/short-d/short/backend/app/adapter/facebook"
"github.com/short-d/short/backend/app/adapter/request"
"github.com/short-d/short/backend/app/adapter/sqldb"
"github.com/short-d/short/backend/app/usecase/sso"
)
Expand Down Expand Up @@ -36,6 +37,10 @@ func NewFacebookAccountLinker(
return facebook.AccountLinker(factory.NewAccountLinker(facebookSSORepo))
}

func NewInstrumentationFactory() request.InstrumentationFactory {

}

// NewFacebookSSO creates FacebookSingleSignOn.
func NewFacebookSSO(
ssoFactory sso.Factory,
Expand All @@ -47,6 +52,7 @@ func NewFacebookSSO(
ssoFactory.NewSingleSignOn(
identityProvider,
account,
sso.AccountLinker(linker)),
sso.AccountLinker(linker),
facebook.NewInstrumentation()),
)
}
1 change: 1 addition & 0 deletions backend/dep/provider/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func NewGithubSSO(
identityProvider,
account,
sso.AccountLinker(accountLinker),
github.NewInstrumentationFactory(),
),
)
}
3 changes: 2 additions & 1 deletion backend/dep/provider/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func NewGoogleSSO(
ssoFactory.NewSingleSignOn(
identityProvider,
account,
sso.AccountLinker(linker)),
sso.AccountLinker(linker),
google.NewInstrumentationFactory()),
)
}

Expand Down
1 change: 1 addition & 0 deletions backend/dep/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var observabilitySet = wire.NewSet(
network.NewProxy,
request.NewClient,
request.NewInstrumentationFactory,
request.NewSSOInstrumentationFactory,
)

var githubAPISet = wire.NewSet(
Expand Down