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); }
private void ComboBoxProviders_SelectedIndexChanged(object sender, EventArgs e) { TextBoxServer.Text = _getServerAddressByProvider(ComboBoxProviders.SelectedIndex); ComboBoxPorts.Enabled = ( ComboBoxProviders.SelectedIndex == OauthProvider.MsLiveProvider || ComboBoxProviders.SelectedIndex == OauthProvider.GoogleSmtpProvider); switch (ComboBoxProviders.SelectedIndex) { case OauthProvider.GoogleSmtpProvider: _oauthWrapper = new OauthDesktopWrapper(OauthProvider.CreateGoogleSmtpProvider()); break; case OauthProvider.MsLiveProvider: _oauthWrapper = new OauthDesktopWrapper(OauthProvider.CreateMsLiveProvider()); break; case OauthProvider.MsOffice365Provider: _oauthWrapper = new OauthDesktopWrapper(OauthProvider.CreateMsOffice365Provider()); break; case OauthProvider.GoogleGmailApiProvider: _oauthWrapper = new OauthDesktopWrapper(OauthProvider.CreateGmailApiProvider()); break; default: throw new Exception("Invalid OAUTH provider!"); } }
private void ListProviders_SelectionChanged(object sender, SelectionChangedEventArgs e) { switch (ListProviders.SelectedIndex) { case OauthProvider.GoogleProvider: TextServer.Text = "smtp.gmail.com"; ListPorts.IsEnabled = true; _oauthWrapper = new OauthDesktopWrapper(OauthProvider.CreateGoogleProvider()); break; case OauthProvider.MsLiveProvider: TextServer.Text = "smtp.live.com"; ListPorts.IsEnabled = true; _oauthWrapper = new OauthDesktopWrapper(OauthProvider.CreateMsLiveProvider()); break; case OauthProvider.MsOffice365Provider: TextServer.Text = "outlook.office365.com"; ListPorts.IsEnabled = false; _oauthWrapper = new OauthDesktopWrapper(OauthProvider.CreateMsOffice365Provider()); break; default: throw new Exception("Invalid OAUTH provider!"); } }
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(); }