auth icon indicating copy to clipboard operation
auth copied to clipboard

Allow configuring scopes and extraUserInfo

Open joscha-alisch opened this issue 3 years ago • 5 comments

This adds a new method to add providers that allows to configure additional scopes and a hook that is called with the authenticated HTTP client. This is a draft to resolve issue #97 .

Usage is like this for the GitHub provider for example, which would fetch the orgs/teams a user is in and attach them to the user.Token.

service.AddProviderWithOptions("github", "cid", "csecret", []string{"read:org"}, func(c *http.Client, u token.User) token.User {
    gh := github.NewClient(c)
    t, _, _ := gh.Teams.ListUserTeams(context.Background(), &github.ListOptions{})
    
    var teams []string
    for _, team := range t {
	    teams = append(teams, fmt.Sprintf("%s:%s", team.Organization.GetLogin(), team.GetName()))
    }
    
    u.SetSliceAttr("teams", teams)
    return u
})

joscha-alisch avatar Oct 06 '21 10:10 joscha-alisch

Pull Request Test Coverage Report for Build 1311457085

  • 4 of 17 (23.53%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-4.8%) to 90.734%

Changes Missing Coverage Covered Lines Changed/Added Lines %
auth.go 4 17 23.53%
<!-- Total: 4 17
Totals Coverage Status
Change from base Build 1201515370: -4.8%
Covered Lines: 235
Relevant Lines: 259

💛 - Coveralls

coveralls avatar Oct 11 '21 22:10 coveralls

it would be nice to cover the change with tests. almost 5% coverage decrease by itself is not such a problem, however not having any tests for extra functionality - is a problem.

umputun avatar Oct 11 '21 22:10 umputun

Certainly :) this was not intended as a ready-to-merge PR, but rather as a first iteration to get feedback on the direction. Hence the draft PR.

I'll go ahead and add tests.

joscha-alisch avatar Oct 12 '21 06:10 joscha-alisch

@joscha-alisch I'm not sure if you expect me to review the PR as it is marked as draft

umputun avatar Oct 30 '21 17:10 umputun

No, i Just didn't have time to add the tests yet. Will let you know when it's ready :)

joscha-alisch avatar Oct 31 '21 13:10 joscha-alisch