Skip to content

Updated SetScope implementation in Options for Facebook and Apple Connection #531

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 34 additions & 4 deletions management/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,27 @@ type ConnectionOptionsFacebook struct {

// Scopes returns the scopes for ConnectionOptionsFacebook.
func (c *ConnectionOptionsFacebook) Scopes() []string {
return tag.Scopes(c)
return strings.Fields(c.GetScope())
}

// SetScopes sets the scopes for ConnectionOptionsFacebook.
func (c *ConnectionOptionsFacebook) SetScopes(enable bool, scopes ...string) {
tag.SetScopes(c, enable, scopes...)
scopeMap := make(map[string]bool)
for _, scope := range c.Scopes() {
scopeMap[scope] = true
}
for _, scope := range scopes {
scopeMap[scope] = enable
}
scopeSlice := make([]string, 0, len(scopeMap))
for scope, enabled := range scopeMap {
if enabled {
scopeSlice = append(scopeSlice, scope)
}
}
sort.Strings(scopeSlice)
scope := strings.Join(scopeSlice, " ")
c.Scope = &scope
}

// ConnectionOptionsApple is used to configure an Apple Connection.
Expand All @@ -799,12 +814,27 @@ type ConnectionOptionsApple struct {

// Scopes returns the scopes for ConnectionOptionsApple.
func (c *ConnectionOptionsApple) Scopes() []string {
return tag.Scopes(c)
return strings.Fields(c.GetScope())
}

// SetScopes sets the scopes for ConnectionOptionsApple.
func (c *ConnectionOptionsApple) SetScopes(enable bool, scopes ...string) {
tag.SetScopes(c, enable, scopes...)
scopeMap := make(map[string]bool)
for _, scope := range c.Scopes() {
scopeMap[scope] = true
}
for _, scope := range scopes {
scopeMap[scope] = enable
}
scopeSlice := make([]string, 0, len(scopeMap))
for scope, enabled := range scopeMap {
if enabled {
scopeSlice = append(scopeSlice, scope)
}
}
sort.Strings(scopeSlice)
scope := strings.Join(scopeSlice, " ")
c.Scope = &scope
}

// ConnectionOptionsLinkedin is used to configure a Linkedin Connection.
Expand Down
Loading