Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - generic auth port #9

Closed
wants to merge 2 commits into from
Closed

WIP - generic auth port #9

wants to merge 2 commits into from

Conversation

danielpoe
Copy link
Member

No description provided.


import (
"flamingo.me/dingo"
interfaces2 "flamingo.me/flamingo/v3/core/auth/interfaces"
Copy link
Member

Choose a reason for hiding this comment

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

AFAIS there's no need to use the alias.

Suggested change
interfaces2 "flamingo.me/flamingo/v3/core/auth/interfaces"
"flamingo.me/flamingo/v3/core/auth/interfaces"


type (
// Idendity information
Idendity interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Identity

Roles() []securityDomain.Role
}

//SimpleUser - implements User and can be used
Copy link
Contributor

Choose a reason for hiding this comment

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

As we will use godoc please format the comments like

// SimpleUser is a default implementation of the User interface...

and not

//SimpleUser - implements User ...

https://golang.org/doc/effective_go.html#commentary


//SimpleUser - implements User and can be used
SimpleUser struct {
SubjectVal string
Copy link
Contributor

Choose a reason for hiding this comment

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

Run gofmt please



// CustomField - get a customfield by key
func (u *SimpleUser) CustomField(key string) (string,bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify method by doing

val, ok := u.CustomFieldVal[key]
return val, ok


//AuthAction - default auth action - starting the authorsation with the registered Authservice
func (c *Authcontroller) AuthAction(ctx context.Context, r *web.Request) web.Result {
redirecturl, ok := r.Params["redirecturl"]
Copy link
Contributor

Choose a reason for hiding this comment

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

You can safely omit the ok variable here, the default value for string is ""


// Inject for Authservice
func (o *Authservice) Inject(responder *web.Responder, config *struct {
Users config.Slice `inject:"config:basicauth.users,optional"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe users should be provided via something like a UserProvider? So the credentials do not have to be in the config?


func (a *Authservice) IsAuthenticated(ctx context.Context, r *web.Request) bool {
_, _, ok := r.Request().BasicAuth()
//TODO check user pw
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be done

EmailVal *string
NameVal *string
CustomFieldVal map[string]string
DefaultRole string
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the DefaultRole?

Copy link
Member

@Ompluscator Ompluscator left a comment

Choose a reason for hiding this comment

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

Couple of remainders:

  1. AuthStarted/AuthStart and AuthDestroyed/SessionDestroyed events.
  2. New RoleProvider in auth module to add read roles from User and returns them.
  3. Unit testing - in general, we introduced interfaces everywhere, so it should not be a problem.
  4. Fake adapters for different AuthServices and maybe generic FakeUserRepository (UserProvider) in auth module which can provide functionality for reading user from csv/yaml, so other fake adapters can use it to provide user data depending on credentials.

Groups []string
User interface {
Subject() string
Email() (string,bool)
Copy link
Member

Choose a reason for hiding this comment

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

I would go with single return argument, with default value as empty string. In general it would be easier for further usage and easy to check for empty string if it's needed.

type (
//Authservice - generic Authservice interface that should be used
Authservice interface {
Authenticate(ctx context.Context, returnURL *url.URL) (web.Result, error)
Copy link
Member

Choose a reason for hiding this comment

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

As remainder to add web.Request in a list of arguments. We can omit to pass returnUrl - making of returnUrl is provided in security middleware, and it can be from header referrer or defined path in config (but, it doesn't hurt if we keep it).

)

type (
Authcontroller struct {
Copy link
Member

Choose a reason for hiding this comment

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

Camel case: "AuthController"

type (
Authcontroller struct {
responder *web.Responder
authservice Authservice
Copy link
Member

Choose a reason for hiding this comment

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

Camel cases and map of services: authServices map[string]AuthService

redirecturl = r.Request().Referer()
}

if refURL, err := url.Parse(redirecturl); err != nil || refURL.Host != r.Request().Host {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure should we have this logic here: there is same functionality in security middleware, so we can either move that here completely or we just read "redirecturl" Param and pass url or nil as argument.

return c.responder.ServerError(errors.New("wrong redirect url given"))
}
return result
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add also Logout action?

@@ -0,0 +1,74 @@
package interfaces
Copy link
Member

Choose a reason for hiding this comment

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

Reminder: to have basicauth as module in separate repository.

@bastianccm
Copy link
Contributor

Superseded by #50

@bastianccm bastianccm closed this Jan 7, 2020
@bastianccm bastianccm deleted the generic_auth branch February 26, 2020 13:59
bastianccm pushed a commit that referenced this pull request Mar 16, 2020
 # Please enter the commit message for your changes. Lines starting
 # with '#' will be kept; you may remove them yourself if you want to.
 # An empty message aborts the commit.
 #
 # Date:      Tue Jan 2 10:05:29 2018 +0100
 #
 # On branch 9-circuit-breaker
 # Changes to be committed:
 #	new file:   core/circuitbreaker/circuitbreaker.go
 #
bastianccm added a commit that referenced this pull request Mar 16, 2020
Resolve "framework/core?: circuitbreaker support"

Closes #9

See merge request shared/flamingo/flamingo!30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants