Exemple #1
0
        void _initOauthWrapper()
        {
            /*
             * To use Google OAUTH in your application, you must create a project in Google Developers Console.
             *
             * - Create your project at https://console.developers.google.com/project.
             * - Select your project -> APIs & Services -> Dashboard -> Credentials;
             * - Credentials -> Create Credentials -> OAuth client ID -> Web application or Other (Desktop Application).
             *  It depends on your application type.
             *
             * - Input a name for your application, input your current ASP/ASP.NET URL at Authorized redirect URIs,
             *  for example: http://localhost/gmailoauth/default.aspx. (Desktop Application doesn't require this step)
             *  Click "Create", you will get your client id and client secret.
             *
             * - Finally you can also set detail information for your project at Credentials -> OAuth consent screen.
             * - If you used https://mail.google.com scope, you should verify your application that is inroduced in cosent screen.
             *  If you don't verify your application, your application is limited by some conditions.
             *
             * You must apply for your client id and client secret, don't use the client id in the sample project, because it is limited now.
             *
             *
             * You must apply for your client id and client secret, don't use the client id in the sample project, because it is limited now.
             * If you got "This app isn't verified" information, please click "advanced" -> Go to ... for test.
             */
            OauthProviderInterface provider = GoogleOauthProvider.Create("1072602369179-aru4rj97ateiho9rt4pf5i8l1r01mc16.apps.googleusercontent.com",
                                                                         "Lnw8r5FvfKFNS_CSEucbdIE-");

            _oauthWrapper = new OauthDesktopWrapper(provider);
        }
Exemple #2
0
        private OauthWebWrapper _initOauthWrapper()
        {
            var OauthWrapper = Session["OauthWrapper"] as OauthWebWrapper;

            if (OauthWrapper != null)
            {
                return(OauthWrapper);
            }

            /*
             * To use Google OAUTH in your application, you must create a project in Google Developers Console.
             *
             * - Create your project at https://console.developers.google.com/project.
             * - Select your project -> APIs & Services -> Dashboard -> Credentials;
             * - Credentials -> Create Credentials -> OAuth client ID -> Web application or Other (Desktop Application).
             * It depends on your application type.
             *
             * - Input a name for your application, input your current ASP/ASP.NET URL at Authorized redirect URIs,
             * for example: http://localhost/gmailoauth/default.aspx. (Desktop Application doesn't require this step)
             * Click "Create", you will get your client id and client secret.
             *
             * - Finally you can also set detail information for your project at Credentials -> OAuth consent screen.
             * - If you used https://mail.google.com scope, you should verify your application that is inroduced in cosent screen.
             * If you don't verify your application, your application is limited by some conditions.
             *
             * You must apply for your client id and client secret, don't use the client id in the sample project, because it is limited now.
             * If you got \"This app isn't verified\" information, please click \"advanced\" -> Go to ... for test.
             */
            OauthProviderInterface provider = GoogleOauthProvider.Create("1072602369179-prgq7tkc834li6ao3fd11r6f2mpc1hdq.apps.googleusercontent.com",
                                                                         "zRqEjYMLJwvfacYA_vUH_6M4",
                                                                         "email%20profile%20https://mail.google.com",
                                                                         "http://localhost:54098/gmailoauth/token"); // add this to Authorized redirect URIs

            OauthWrapper            = new OauthWebWrapper(provider);
            Session["OauthWrapper"] = OauthWrapper;
            return(OauthWrapper);
        }
 public OauthDesktopWrapper(OauthProviderInterface oauthProvider)
 {
     _provider = oauthProvider;
 }
Exemple #4
0
 public OauthWebWrapper(OauthProviderInterface oauthProvider)
 {
     _provider = oauthProvider;
 }
Exemple #5
0
        private async Task _doOauthAsync()
        {
            if (_oauthWrapper == null)
            {
                /*
                 *  To use Google OAUTH in your application, you must create a project in Google Developers Console.
                 *
                 * - Create your project at https://console.developers.google.com/project.
                 * - Select your project -> APIs & Services -> Dashboard -> Credentials;
                 * - Credentials -> Create Credentials -> OAuth client ID -> Web application or Other (Desktop Application).
                 *  It depends on your application type.
                 *
                 * - Input a name for your application, input your current ASP/ASP.NET URL at Authorized redirect URIs,
                 *  for example: http://localhost/gmailoauth/default.aspx. (Desktop Application doesn't require this step)
                 *  Click "Create", you will get your client id and client secret.
                 *
                 * - Finally you can also set detail information for your project at Credentials -> OAuth consent screen.
                 * - If you used https://mail.google.com scope, you should verify your application that is inroduced in cosent screen.
                 *  If you don't verify your application, your application is limited by some conditions.
                 *
                 * You must apply for your client id and client secret, don't use the client id in the sample project, because it is limited now.
                 * If you got "This app isn't verified" information, please click "advanced" -> Go to ... for test.
                 */
                OauthProviderInterface provider = GoogleOauthProvider.Create("1072602369179-aru4rj97ateiho9rt4pf5i8l1r01mc16.apps.googleusercontent.com",
                                                                             "Lnw8r5FvfKFNS_CSEucbdIE-");
                _oauthWrapper = new OauthDesktopWrapper(provider);
            }

            // AccessToken is existed, if it is not expired, use it directly, otherwise refresh it.
            if (!string.IsNullOrEmpty(_oauthWrapper.OauthProvider.AccessToken))
            {
                if (!_oauthWrapper.IsAccessTokenExpired)
                {
                    return;
                }

                TextStatus.Text = "Refreshing access token ...";
                try
                {
                    await _oauthWrapper.RefreshAccessTokenAsync();

                    return;
                }
                catch
                {
                    TextStatus.Text = "Failed to refresh access token, try to get a new access token ...";
                }
            }

            OauthBrowser.Navigate(
                new Uri(_oauthWrapper.OauthProvider.GenerateFullAuthUri())
                );

            ShowOauthPanel(true);
            while (OauthViewer.Visibility != Visibility.Collapsed)
            {
                await Task.Delay(100);
            }

            TextStatus.Text = "Requesting access token ...";
            await _oauthWrapper.RequestAccessTokenAndUserEmailAsync();
        }