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

Unable to fetch Organisations list if membership is private #2470

Closed
JyotstnaDeviChintala opened this issue Jun 30, 2022 · 5 comments · Fixed by #2487
Closed

Unable to fetch Organisations list if membership is private #2470

JyotstnaDeviChintala opened this issue Jun 30, 2022 · 5 comments · Fixed by #2487
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@JyotstnaDeviChintala
Copy link

JyotstnaDeviChintala commented Jun 30, 2022

i have an C# wpf Desktop APP trying to fetch the organizations list i have access to or i'm a member of

This app has been added to trusted apps to my account and by the organization ( i own) also
Applications ->Authorised OAUth APPs ->MYAPP, its trusted by the Organization too.

Scopes used are : user and read:org while fetching access token

But still using this token im unable to fetch full organizations list.

Organizations in which my membership is Public are being retrieved.

but for Organizations in which my membership is Private are not retrieved.

is this expected?

@timrogers
Copy link
Contributor

@JyotstnaDeviChintala Thanks for reaching out. Happy to try to help on this!

Can you share your code, just so we can see what API you're calling?

What kind of API credential are you using? Is it an OAuth access token, a personal access token, something else...?

@JyotstnaDeviChintala
Copy link
Author

JyotstnaDeviChintala commented Jun 30, 2022

Thankyou for your support. Heres the code:

Fetching organizations list

List<string> organizationList = new List<string>();
            try
            {
                if (GitHubAccessToken != null)
                {
                    var user = await client.User.Current();
                    IReadOnlyList<Organization> organizations = await client.Organization.GetAllForUser(user.Login);
                    foreach (Organization organization in organizations)
                        organizationList.Add(organization.Login);
                }
            }

using OAuth access token with scopes:

var request = new OauthLoginRequest(clientId)
                {
                    Scopes = { "user", "notifications", "repo", "read:org" },
                    State = csrf
                };

@timrogers
Copy link
Contributor

@JyotstnaDeviChintala Thanks for sharing the code!

According to the API docs, that API "only lists public memberships, regardless of authentication". You'll need to use the "list organizations for the authenticated user" API instead.

Can you try using the GetAllForCurrent method instead?

@JyotstnaDeviChintala
Copy link
Author

JyotstnaDeviChintala commented Jul 1, 2022

Thanks a lot ! it Worked.

Doc was not clear and i got confused with the library documentation

    ```

//
// Summary:
// Returns all Octokit.Organizations for the specified user.
//
// Returns:
// A list of the specified user's Octokit.Organizations.
//
// Exceptions:
// T:Octokit.ApiException:
// Thrown when a general API error occurs.
Task<IReadOnlyList> GetAllForUser(string user);

@timrogers
Copy link
Contributor

Thanks a lot ! it Worked.

Doc was not clear and i got confused with the library documentation

    ```

// // Summary: // Returns all Octokit.Organizations for the specified user. // // Returns: // A list of the specified user's Octokit.Organizations. // // Exceptions: // T:Octokit.ApiException: // Thrown when a general API error occurs. Task GetAllForUser(string user);

Great! If you have time, it would be awesome if you could make a pull request updating the method description to make the "only lists public memberships, regardless of authentication" limitation clear. That'll help other people in the future I'm sure.

timrogers added a commit that referenced this issue Jul 15, 2022
…lear that only public memberships are returned

Fixes #2470.
@nickfloyd nickfloyd added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Question: using the SDK labels Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
None yet
3 participants