public string GetAuthorizationUrl(string state, GitHubScopeCollection scopes)
        {
            // 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
            string scope = (scopes == null ? "" : scopes.ToString());

            if (!String.IsNullOrWhiteSpace(scope))
            {
                nvc.Add("scope", scope);
            }

            // Generate the URL
            return("https://github.com/login/oauth/authorize?" + SocialUtils.NameValueCollectionToQueryString(nvc));
        }
        public static GitHubOAuthAccessTokenResponse Parse(NameValueCollection nvc)
        {
            GitHubScopeCollection scopes = new GitHubScopeCollection();

            foreach (string scope in (nvc["scope"] ?? "").Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                switch (scope)
                {
                case "user": scopes.Add(GitHubScope.User); break;

                case "user:email": scopes.Add(GitHubScope.UserEmail); break;

                case "user:follow": scopes.Add(GitHubScope.UserFollow); break;

                case "public_repo": scopes.Add(GitHubScope.PublicRepo); break;

                case "repo": scopes.Add(GitHubScope.Repo); break;

                case "repo:status": scopes.Add(GitHubScope.RepoStatus); break;

                case "delete_repo": scopes.Add(GitHubScope.DeleteRepo); break;

                case "notifications": scopes.Add(GitHubScope.Notifications); break;

                case "gist": scopes.Add(GitHubScope.Gist); break;

                default: scopes.Add(new GitHubScope(scope)); break;
                }
            }

            return(new GitHubOAuthAccessTokenResponse {
                AccessToken = nvc["access_token"],
                Scope = scopes,
                TokenType = nvc["token_type"]
            });
        }
        public string GetAuthorizationUrl(string state, GitHubScopeCollection scopes) {

            // 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
            string scope = (scopes == null ? "" : scopes.ToString());
            if (!String.IsNullOrWhiteSpace(scope)) nvc.Add("scope", scope);

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

        }