コード例 #1
0
        public string GetAuthorizationUrl(string state, GitHubScope scope = GitHubScope.Default) {

            // Initialize the query string
            NameValueCollection nvc = new NameValueCollection { { "client_id", ClientId } };

            // Add the redirect URI if specified
            if (!String.IsNullOrWhiteSpace(RedirectUri)) nvc.Add("redirect_uri", RedirectUri);

            // Add the state if specified
            if (!String.IsNullOrWhiteSpace(state)) nvc.Add("state", state);

            // Get the scope list
            List<string> scopes = new List<string>();
            if (scope.HasFlag(GitHubScope.User)) scopes.Add("user");
            if (scope.HasFlag(GitHubScope.UserEmail)) scopes.Add("user:email");
            if (scope.HasFlag(GitHubScope.UserFollow)) scopes.Add("user:follow");
            if (scope.HasFlag(GitHubScope.PublicRepo)) scopes.Add("public_repo");
            if (scope.HasFlag(GitHubScope.Repo)) scopes.Add("repo");
            if (scope.HasFlag(GitHubScope.RepoStatus)) scopes.Add("repo:status");
            if (scope.HasFlag(GitHubScope.DeleteRepo)) scopes.Add("delete_repo");
            if (scope.HasFlag(GitHubScope.Notifications)) scopes.Add("notifications");
            if (scope.HasFlag(GitHubScope.Gist)) scopes.Add("gist");
            if (scopes.Count > 0) nvc.Add("scope", String.Join(",", scopes));

            // Generate the URL
            return "https://github.com/login/oauth/authorize?" + SocialUtils.NameValueCollectionToQueryString(nvc);

        }
コード例 #2
0
        public string GetAuthorizationUrl(string state, GitHubScope scope = GitHubScope.Default)
        {
            // Initialize the query string
            NameValueCollection nvc = new NameValueCollection {
                { "client_id", ClientId }
            };

            // Add the redirect URI if specified
            if (!String.IsNullOrWhiteSpace(RedirectUri))
            {
                nvc.Add("redirect_uri", RedirectUri);
            }

            // Add the state if specified
            if (!String.IsNullOrWhiteSpace(state))
            {
                nvc.Add("state", state);
            }

            // Get the scope list
            List <string> scopes = new List <string>();

            if (scope.HasFlag(GitHubScope.User))
            {
                scopes.Add("user");
            }
            if (scope.HasFlag(GitHubScope.UserEmail))
            {
                scopes.Add("user:email");
            }
            if (scope.HasFlag(GitHubScope.UserFollow))
            {
                scopes.Add("user:follow");
            }
            if (scope.HasFlag(GitHubScope.PublicRepo))
            {
                scopes.Add("public_repo");
            }
            if (scope.HasFlag(GitHubScope.Repo))
            {
                scopes.Add("repo");
            }
            if (scope.HasFlag(GitHubScope.RepoStatus))
            {
                scopes.Add("repo:status");
            }
            if (scope.HasFlag(GitHubScope.DeleteRepo))
            {
                scopes.Add("delete_repo");
            }
            if (scope.HasFlag(GitHubScope.Notifications))
            {
                scopes.Add("notifications");
            }
            if (scope.HasFlag(GitHubScope.Gist))
            {
                scopes.Add("gist");
            }
            if (scopes.Count > 0)
            {
                nvc.Add("scope", String.Join(",", scopes));
            }

            // Generate the URL
            return("https://github.com/login/oauth/authorize?" + SocialUtils.NameValueCollectionToQueryString(nvc));
        }