public static async Task LogIn(IDialogContext context)
        {
            GitHubClient client = new GitHubClient(new ProductHeaderValue(Constants.ProductHeader));

            ConversationReference cr = context.Activity.ToConversationReference();

            IMessageActivity reply = context.MakeMessage();

            string csrf = Membership.GeneratePassword(24, 1);

            context.UserData.SetValue(Constants.StateKey, csrf);

            OauthLoginRequest request = new OauthLoginRequest(ConfigurationManager.AppSettings[Constants.GitHubClientIdKey])
            {
                Scopes      = { "repo" },
                State       = csrf,
                RedirectUri = GetRedirectUri(cr)
            };

            Uri loginUrl = client.Oauth.GetGitHubLoginUrl(request);

            reply.Text = "Please login to GitHub using the button below.";

            SigninCard card = SigninCard.Create("Authorize me to access your GitHub account.", "Login to GitHub", loginUrl.ToString());

            reply.Attachments.Add(card.ToAttachment());

            await context.PostAsync(reply);
        }
        /// <summary>
        /// Opens OAuth window using WebAuthenticationBroker class and returns true is authentication is successful
        /// </summary>
        /// <returns></returns>
        public async Task <bool> Authenticate()
        {
            try
            {
                string clientId = await AppCredentials.GetAppKey();

                OauthLoginRequest request = new OauthLoginRequest(clientId)
                {
                    Scopes = { "user", "repo" },
                };

                Uri oauthLoginUrl = client.Oauth.GetGitHubLoginUrl(request);

                WebAuthenticationResult res = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, oauthLoginUrl, endUri);

                if (res.ResponseStatus == WebAuthenticationStatus.Success)
                {
                    var response = res.ResponseData;
                    return(await Authorize(response));
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
Beispiel #3
0
        public async Task <string> GetOAuthToken(GitHubClient Client, string ClientID, string ClientSecret)
        {
            if (OAuthCodeSource != null)
            {
                Debug.WriteLine("Please do not request multiple tokens at once!", "Warning");
                return(string.Empty);
            }

            OauthLoginRequest Request = new OauthLoginRequest(ClientID)
            {
                Scopes = { "user", "notifications" }
            };

            Uri OAuthLoginUrl = Client.Oauth.GetGitHubLoginUrl(Request);

            Debug.WriteLine($"Logging into: {OAuthLoginUrl.AbsoluteUri}");
            Browser.Address = OAuthLoginUrl.AbsoluteUri;
            //Browser.Navigate(OAuthLoginUrl);

            OAuthCodeSource = new TaskCompletionSource <string>();
            string Code = await OAuthCodeSource.Task;

            Debug.WriteLine("Get code: " + Code);

            if (Code.IsNullOrEmpty())
            {
                OAuthCodeSource = null;
                return(string.Empty);
            }

            string OAuthToken = await GenerateTokenFromOAuth(Client, ClientID, ClientSecret, Code);

            OAuthCodeSource = null;
            return(OAuthToken);
        }
Beispiel #4
0
        internal void ShowOAuthLogin()
        {
            var request = new OauthLoginRequest(Secret.clientId)
            {
                Scopes = { "user", "notifications" }
            };

            Device.OpenUri(SessionManager.Client.Oauth.GetGitHubLoginUrl(request));
        }
Beispiel #5
0
        /// <inheritdoc />
        public Uri GetAuthorizationURL(Uri callbackURL)
        {
            logger.LogTrace("GetAuthorizationURL for {0}", callbackURL);
            var olr = new OauthLoginRequest(gitHubConfiguration.OauthClientID);

            olr.Scopes.Add(RequiredScope);              //all we need
            olr.RedirectUri = callbackURL;
            return(gitHubClient.Oauth.GetGitHubLoginUrl(olr));
        }
Beispiel #6
0
        /// <summary>
        /// Generates an OauthLoginRequest and uses it to obtain the login URL.
        /// </summary>
        static public Uri GetLoginUrl()
        {
            var request = new OauthLoginRequest(ApiKeys.API_KEY)
            {
                Scopes = { "user", "repo", "notifications" }
            };

            return(client.Oauth.GetGitHubLoginUrl(request));
        }
Beispiel #7
0
        private Uri GetOAuthLogin()
        {
            var csrf    = System.Web.Security.Membership.GeneratePassword(24, 1);
            var request = new OauthLoginRequest(CLIENT_ID)
            {
            };
            var uri = client.Oauth.GetGitHubLoginUrl(request);

            return(uri);
        }
        public Uri OAuthLogin()
        {
            var request = new OauthLoginRequest(clientId)
            {
                Scopes = { "read:user", "public_repo" }
            };
            var oauthLoginUrl = client.Oauth.GetGitHubLoginUrl(request);

            return(oauthLoginUrl);
        }
Beispiel #9
0
        public static void CreateOauthenUri()
        {
            var request = new OauthLoginRequest(Const.clientId)
            {
                Scopes = { "user", "notifications" },
            };

            var oauthLoginUrl = Core.client.Oauth.GetGitHubLoginUrl(request);

            LaunchUri(oauthLoginUrl);
        }
        public string GetOAuthLink()
        {
            var request = new OauthLoginRequest(_githubConfiguration.ClientId)
            {
                Scopes      = { "user", "gist", "repo" },
                RedirectUri = new Uri(_webHostService.GetGithubLoginRedirectUrl())
            };

            var oauthLoginUrl = Client.Oauth.GetGitHubLoginUrl(request);

            return(oauthLoginUrl.ToString());
        }
Beispiel #11
0
        public ActionResult Login()
        {
            var oauthLoginRequest = new OauthLoginRequest(_clientId);

            oauthLoginRequest.Scopes.Add("user");
            oauthLoginRequest.Scopes.Add("public_repo");
            //oauthLoginRequest.Scopes.Add("private_repo");

            var loginUrl = _github.Oauth.GetGitHubLoginUrl(oauthLoginRequest);

            return(Redirect(loginUrl.ToString()));
        }
        public Uri GetOauthRequestUrl(string clientId, string clientSecret, string csrfToken)
        {
            Trace.TraceInformation("Beginning OAuth request");

            var request = new OauthLoginRequest(clientId)
            {
                Scopes = { "user", "repo" },
                State  = csrfToken
            };

            return(GitHubClient().Oauth.GetGitHubLoginUrl(request));
        }
        public async Task Handle(HttpRequest request, HttpResponse response, RouteData routeData)
        {
            // We should know the TenantID and user ID here
            var loginRequest = new OauthLoginRequest(_credentials.OAuthClientID)
            {
                State = _tokenStore.GenerateStateForCurrentUser(request.Query["callback"].Single())
            };
            var client = await _clientFactory.NewUnauthenticatedClient();

            response.StatusCode          = StatusCodes.Status307TemporaryRedirect;
            response.Headers["Location"] = client.Oauth.GetGitHubLoginUrl(loginRequest).ToString();
        }
Beispiel #14
0
        public async Task LoginGitHub(HttpRequestMessage request)
        {
            var content = await request.Content.ReadAsStringAsync();

            var data = HttpUtility.ParseQueryString(content);

            // アクセストークン保存の為のユーザデータを格納
            _userData = data;

            // ===========================
            // GitHub OauthURL取得
            // ===========================
            var csrf = Membership.GeneratePassword(20, 0);

            var oauthRequest = new OauthLoginRequest(ConfigurationManager.AppSettings["client_id"])
            {
                Scopes = { "repo", "user" },
                State  = csrf
            };

            var url = _githubClient.Oauth.GetGitHubLoginUrl(oauthRequest).ToString();

            // ==============================
            // Oauth用リダイレクトボタン作成
            // ==============================
            var model = new PostMessageModel()
            {
                Channel       = data["channel_id"],
                Text          = "GitHubへログインしてください",
                Response_type = "ephemeral",
                Attachments   = new List <Attachment>()
                {
                    new Attachment()
                    {
                        Fallback = "The GitHub Oauth URL",
                        Actions  = new List <Action>()
                        {
                            new Action()
                            {
                                Type  = "button",
                                Name  = "github_oauth_url",
                                Text  = "ログイン",
                                Url   = url,
                                Style = "primary"
                            }
                        }
                    }
                }
            };

            await SlackApi.ExecutePostApiAsJson(model, data["response_url"], data["team_id"]);
        }
Beispiel #15
0
        public string GetConsentUrl(string state)
        {
            var request = new OauthLoginRequest(_settings.GitHub.ClientId)
            {
                RedirectUri = new Uri(_settings.GitHub.RedirectUrl),
                State       = state,
                Scopes      = { "admin:repo_hook" }
            };

            var oauthLoginUrl = _client.Oauth.GetGitHubLoginUrl(request);

            return(oauthLoginUrl.AbsoluteUri);
        }
Beispiel #16
0
        public ActionResult GithubConnection()
        {
            var clientId = "Iv1.81c9b324b18a4188";
            var client   = new GitHubClient(new ProductHeaderValue("AreaNet"));
            var request  = new OauthLoginRequest(clientId)
            {
                Scopes      = { "user", "notifications" },
                RedirectUri = new Uri("http://localhost:5000/Github/GithubAuthorized")
            };
            var oauthLoginUrl = client.Oauth.GetGitHubLoginUrl(request);

            return(Redirect(oauthLoginUrl.ToString()));
        }
Beispiel #17
0
        /// <summary>
        /// Build OAuth Request URL
        /// </summary>
        /// <returns>OAuthUrl</returns>
        private string GetOauthLoginUrl()
        {
            // 1. Redirect users to request GitHub access
            var request = new OauthLoginRequest(clientId)
            {
                Scopes = { "user", "notifications" }
            };
            var oauthLoginUrl = client.Oauth.GetGitHubLoginUrl(request);

            Console.WriteLine(oauthLoginUrl);
            Debug.WriteLine(oauthLoginUrl);
            return(oauthLoginUrl.ToString());
        }
Beispiel #18
0
        private string GetOauthLoginUrl()
        {
            string csrf = Membership.GeneratePassword(24, 1);
            Session["CSRF:State"] = csrf;

            // 1. Redirect users to request GitHub access
            var request = new OauthLoginRequest(clientId)
            {
                Scopes = { "user", "notifications" },
                State = csrf
            };
            var oauthLoginUrl = client.Oauth.GetGitHubLoginUrl(request);
            return oauthLoginUrl.ToString();
        }
Beispiel #19
0
        public static async Task DoAuthorizationViaBrowserAsync()
        {
            var request = new OauthLoginRequest(GitHubClientBase.ClientId);

            GitHubClientBase.Scopes.ForEach(request.Scopes.Add);

            var oauthLoginUrl = GitHubClientBase.Instance.Oauth.GetGitHubLoginUrl(request);
            var result        = await Launcher.LaunchUriAsync(oauthLoginUrl);

            if (!result)
            {
                Log.Error($"An error occurred while opening oauth uri ({oauthLoginUrl})");
            }
        }
        /// <inheritdoc/>
        public override void ConfigureAuthenticationModule(NancyModule module)
        {
            module.Get["/auth/{token}"] = args =>
            {
                User user;
                if (!User.TryGetByToken(args.token, out user))
                {
                    return(HttpStatusCode.BadRequest);
                }

                var request = new OauthLoginRequest(ClientId)
                {
                    RedirectUri = new Uri(Domain, "auth/after-auth/" + user.Token)
                };
                request.Scopes.Add("repo");
                request.Scopes.Add("user:email");

                return(module.Response.AsRedirect(authClient.Oauth.GetGitHubLoginUrl(request).AbsoluteUri));
            };

            module.Get["/after-auth/{token}", true] = async(args, ct) =>
            {
                User user;
                if (!User.TryGetByToken(args.token, out user))
                {
                    // Eh, well.
                    return(HtmlHelpers.CreateHtmlPage(
                               "Session expired",
                               "<h1>Oops.</h1> <div>Something went wrong. Your session token probably expired. " +
                               "Trying again might work.</div>"));
                }

                // Extend the user's lifetime so they don't die on us.
                user.ExtendLifetime(AuthenticationModule.AuthenticatedUserLifetime);

                // Request an OAuth token.
                var request = new OauthTokenRequest(
                    ClientId,
                    ClientSecret,
                    module.Request.Query.code);

                // Store it.
                user.ContentTrackerToken = new GitHubContentTrackerToken(
                    await authClient.Oauth.CreateAccessToken(request));

                return(HtmlHelpers.CreateHtmlPage(
                           "Authentication successful",
                           "<h1>You did it!</h1> <div>Yay! You successfully managed to authenticate! 🎉</div>"));
            };
        }
        public virtual async Task <string> GetAuthorizationUrlAsync(string socketId)
        {
            var client = new GitHubClient(new ProductHeaderValue(AppConstants.ProductHeaderValue));

            var request = new OauthLoginRequest(_githubClientParameters.ClientId)
            {
                Scopes = { "user", "notifications" },
                State  = socketId
            };

            var oauthLoginUrl = client.Oauth.GetGitHubLoginUrl(request);

            return(oauthLoginUrl.ToString());
        }
Beispiel #22
0
        private string GetOauthLoginUrl()
        {
            string csrf = Membership.GeneratePassword(24, 1);

            Session["CSRF:State"] = csrf;
            // 1. Redirect users to request GitHub access
            var request = new OauthLoginRequest(GitScanAppConfig.GetValue(Constants.GlobalSection, Constants.ClientIdKey))
            {
                Scopes = { "repo" },
                State  = csrf
            };
            var oauthLoginUrl = GetGitHubClient().Oauth.GetGitHubLoginUrl(request);

            return(oauthLoginUrl.ToString());
        }
        public void GetAccessToken()
        {
            string csrf = Membership.GeneratePassword(24, 1);
            //Session["CSRF:State"] = csrf;

            var request = new OauthLoginRequest(ClientId)
            {
                Scopes = { "user", "notifications" },
                State  = csrf
            };

            // NOTE: user must be navigated to this URL
            var oauthLoginUrl = Client.Oauth.GetGitHubLoginUrl(request);
            //.
        }
Beispiel #24
0
        Uri GetLoginUrl(IOauthClient client, string state)
        {
            var request = new OauthLoginRequest(ApiClientConfiguration.ClientId);

            request.State = state;

            foreach (var scope in requestedScopes)
            {
                request.Scopes.Add(scope);
            }

            var uri = client.GetGitHubLoginUrl(request);

            // OauthClient.GetGitHubLoginUrl seems to give the wrong URL. Fix this.
            return(new Uri(uri.ToString().Replace("/api/v3", "")));
        }
        private Response RedirectToOAuth()
        {
            var csrf = Guid.NewGuid().ToString();

            Session["CSRF:State"] = csrf;
            Session["OrigUrl"]    = this.Request.Path;

            var request = new OauthLoginRequest(clientId)
            {
                Scopes = { "repo:status" },
                State  = csrf
            };
            var oauthLoginUrl = client.Oauth.GetGitHubLoginUrl(request);

            return(Response.AsRedirect(oauthLoginUrl.ToString()));
        }
        private String getOauthLoginURL()
        {
            String csrf = Membership.GeneratePassword(24, 1);

            Session["CSRF:State"] = csrf;

            var request = new OauthLoginRequest(CLIENT_ID)
            {
                Scopes = { "user", "notifications" },
                State  = csrf
            };

            var oauthLoginURL = client.Oauth.GetGitHubLoginUrl(request);

            return(oauthLoginURL.ToString());
        }
Beispiel #27
0
        protected string GetOauthLoginUrl()
        {
            string csrf = System.Web.Security.Membership.GeneratePassword(24, 1);

            Session["CSRF:State"] = csrf;

            // 1. Redirect users to request GitHub access
            var request = new OauthLoginRequest(ClientId)
            {
                Scopes = { "user", "notifications", "public_repo", "repo", "write:org" },
                State  = csrf
            };
            var oauthLoginUrl = Client.Oauth.GetGitHubLoginUrl(request);

            return(oauthLoginUrl.ToString());
        }
Beispiel #28
0
        private async Task <string> GetOauthLoginUrl()
        {
            var csrf = Membership.GeneratePassword(24, 1);

            Session["CSRF:State"] = csrf;

            var cd = await DataGetter.GetClientData();

            var request = new OauthLoginRequest(cd.ClientId)
            {
                Scopes = { "user", "notifications" },
                State  = csrf
            };
            var oauthLoginUrl = _client.Oauth.GetGitHubLoginUrl(request);

            return(oauthLoginUrl.ToString());
        }
Beispiel #29
0
        public async Task <Uri> OAuth(string url, ISession session)
        {
            var csrf = StringCipher.Encrypt(Guid.NewGuid().ToString("N"), "CSRF");

            session[SessionKeys.CSRF] = csrf;

            var request = new OauthLoginRequest(clientId)
            {
                Scopes      = { "public_repo", "user" },
                State       = csrf,
                RedirectUri = new Uri(url)
            };

            // NOTE: user must be navigated to this URL
            var oauthLoginUrl = Git.Oauth.GetGitHubLoginUrl(request);

            return(oauthLoginUrl);
        }
        public void ReturnsUrlWithAllParameters()
        {
            var request = new OauthLoginRequest("secret")
            {
                RedirectUri = new Uri("https://example.com/foo?foo=bar"),
                Scopes      = { "foo", "bar" },
                State       = "canARY"
            };
            var connection = Substitute.For <IConnection>();

            connection.BaseAddress.Returns(new Uri("https://api.github.com"));
            var client = new OauthClient(connection);

            var result = client.GetGitHubLoginUrl(request);

            Assert.Equal("/login/oauth/authorize", result.AbsolutePath);
            Assert.Equal("?client_id=secret&redirect_uri=https%3A%2F%2Fexample.com%2Ffoo%3Ffoo%3Dbar&scope=foo%2Cbar&state=canARY", result.Query);
        }
 /// <summary>
 /// Gets the URL used in the first step of the web flow. The Web application should redirect to this URL.
 /// </summary>
 /// <param name="request">Parameters to the Oauth web flow login url</param>
 /// <returns></returns>
 public Uri GetGitHubLoginUrl(OauthLoginRequest request)
 {
     return _client.Oauth.GetGitHubLoginUrl(request);
 }