private void button_Next_Click(object sender, EventArgs e)
        {
            ValidateResult           validateResult;
            AcquireAccessTokenResult acquireAccessTokenResult;

            switch (currentPageIndex)
            {
            case PageIndex.Page00_PortalSelection:
                // Portal selection page

                if (radioButton_Page00_MicrosoftAzurePortal.Checked)
                {
                    // V1 endpoint
                    // Go to the next page.
                    ShowPage(PageIndex.Page01_MicrosoftAzurePortalAppSelection);
                }
                else if (radioButton_Page00_AppRegistrationPortal.Checked)
                {
                    // V2 endpoint
                    // Go to the next page.
                    ShowPage(PageIndex.Page02_AppRegistrationPortalAppSelection);
                }
                else if (radioButton_Page00_BuiltInAppOrBasicAuth.Checked)
                {
                    // The user has no application
                    // Go to the next page.
                    // Create a return value and close this window.
                    ShowPage(PageIndex.Page10_BuiltInAppOrBasicAuthSelection);
                }
                else
                {
                    // The user has the SharePoint Online App-Only REST API
                    // Microsoft Azure Access Control Service application.
                    ShowPage(PageIndex.Page14_SharePointOnlineAppOnlyOptionForm);
                }

                break;

            case PageIndex.Page01_MicrosoftAzurePortalAppSelection:
                // App selection page for V1 auth endpoint.

                if (radioButton_Page01_V1Web.Checked)
                {
                    // V1 endpoint Web App
                    // Go to the next page.
                    ShowPage(PageIndex.Page03_V1WebAppOptionForm);
                }
                else if (radioButton_Page01_V1Native.Checked)
                {
                    // V1 endpoint Native App
                    // Go to the next page.
                    ShowPage(PageIndex.Page04_V1NativeAppOptionForm);
                }
                else if (radioButton_Page01_V1AppOnlyByCert.Checked)
                {
                    // V1 endpoint Web App (App Only Token by certificate)
                    // Go to the next page.
                    ShowPage(PageIndex.Page05_V1AppOnlyByCertOptionForm);
                }
                else if (radioButton_Page01_V1AppOnlyByKey.Checked)
                {
                    // V1 endpoint Web App (App Only Token by Key)
                    // Go to the next page.
                    ShowPage(PageIndex.Page08_V1AppOnlyByKeyOptionForm);
                }
                else
                {
                    // V1 endpoint Admin Consent
                    // Go to the next page.
                    ShowPage(PageIndex.Page09_V1AdminConsentOptionForm);
                }

                break;

            case PageIndex.Page02_AppRegistrationPortalAppSelection:
                // App selection page for V2 auth endpoint.

                if (radioButton_Page02_V2Web.Checked)
                {
                    // V2 endpoint Web App
                    // Go to the next page.
                    ShowPage(PageIndex.Page06_V2WebAppOptionForm);
                }
                else if (radioButton_Page02_V2Mobile.Checked)
                {
                    // V2 endpoint Mobile App
                    // Go to the next page.
                    ShowPage(PageIndex.Page07_V2MobileAppOptionForm);
                }
                else if (radioButton_Page02_V2AdminConsent.Checked)
                {
                    // V2 endpoint, but need admin consent
                    // Go to the next page.
                    ShowPage(PageIndex.Page13_V2AdminConsentOptionForm);
                }
                else if (radioButton_Page02_V2WebAppOnlyForMicrosoftGraph.Checked)
                {
                    // V2 endpoint Web App (App Only Token by password for Microsoft Graph)
                    // Go to the next page.
                    ShowPage(PageIndex.Page12_V2AppOnlyByPasswordForMicrosoftGraphOptionForm);
                }

                break;

            case PageIndex.Page03_V1WebAppOptionForm:
                // Option form for V1 auth endpoint Web App

                V1WebAppUtil v1WebAppUtil = new V1WebAppUtil()
                {
                    ClientID     = textBox_Page03_ClientID.Text,
                    RedirectUri  = textBox_Page03_RedirectUri.Text,
                    Resource     = Util.ConvertResourceNameToResourceEnum(comboBox_Page03_Resource.SelectedItem.ToString()),
                    ClientSecret = textBox_Page03_ClientSecret.Text
                };

                validateResult = v1WebAppUtil.Validate();

                if (validateResult.IsValid)
                {
                    acquireAccessTokenResult = v1WebAppUtil.AcquireAccessToken();

                    if (acquireAccessTokenResult.Success == InteractiveResult.Fail)
                    {
                        MessageBox.Show(acquireAccessTokenResult.ErrorMessage, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (acquireAccessTokenResult.Success == InteractiveResult.Cancel)
                    {
                        return;
                    }

                    TokenResponse tokenResponse = acquireAccessTokenResult.Token;

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV1, Util.ConvertResourceNameToResourceEnum(comboBox_Page03_Resource.SelectedItem.ToString()), textBox_Page03_ClientID.Text, textBox_Page03_ClientSecret.Text, "", textBox_Page03_RedirectUri.Text);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show(string.Join(Environment.NewLine, validateResult.ErrorMessage), "Office365APIEditor");
                }

                break;

            case PageIndex.Page04_V1NativeAppOptionForm:
                // Option form for V1 auth endpoint Native App

                V1NativeAppUtil v1NativeAppUtil = new V1NativeAppUtil()
                {
                    TenantName  = textBox_Page04_TenantName.Text,
                    ClientID    = textBox_Page04_ClientID.Text,
                    RedirectUri = textBox_Page04_RedirectUri.Text,
                    Resource    = Util.ConvertResourceNameToResourceEnum(comboBox_Page04_Resource.SelectedItem.ToString())
                };

                validateResult = v1NativeAppUtil.Validate();

                if (validateResult.IsValid)
                {
                    acquireAccessTokenResult = v1NativeAppUtil.AcquireAccessToken();

                    if (acquireAccessTokenResult.Success == InteractiveResult.Fail)
                    {
                        MessageBox.Show(acquireAccessTokenResult.ErrorMessage, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (acquireAccessTokenResult.Success == InteractiveResult.Cancel)
                    {
                        return;
                    }

                    TokenResponse tokenResponse = acquireAccessTokenResult.Token;

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV1, Util.ConvertResourceNameToResourceEnum(comboBox_Page04_Resource.SelectedItem.ToString()), textBox_Page04_ClientID.Text, "", "", textBox_Page04_RedirectUri.Text);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show(string.Join(Environment.NewLine, validateResult.ErrorMessage), "Office365APIEditor");
                }

                break;

            case PageIndex.Page05_V1AppOnlyByCertOptionForm:
                // Option form for V1 auth endpoint Web App App only token by certificate

                if (ValidateV1WebAppAppOnlyByCertParam())
                {
                    TokenResponse tokenResponse = AcquireV1WebAppAppOnlyAccessTokenByCert();

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV1, Util.ConvertResourceNameToResourceEnum(comboBox_Page05_Resource.SelectedItem.ToString()), textBox_Page05_ClientID.Text, "", "", "");
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }

                break;

            case PageIndex.Page06_V2WebAppOptionForm:
                // Option form for V2 auth endpoint Web App

                V2WebAppUtil v2WebAppUtil = new V2WebAppUtil()
                {
                    TenantName   = textBox_Page06_TenantName.Text,
                    ClientID     = textBox_Page06_ClientID.Text,
                    RedirectUri  = textBox_Page06_RedirectUri.Text,
                    Scopes       = textBox_Page06_Scopes.Text,
                    ClientSecret = textBox_Page06_ClientSecret.Text
                };

                validateResult = v2WebAppUtil.Validate();

                if (validateResult.IsValid)
                {
                    acquireAccessTokenResult = v2WebAppUtil.AcquireAccessToken();

                    if (acquireAccessTokenResult.Success == InteractiveResult.Fail)
                    {
                        MessageBox.Show(acquireAccessTokenResult.ErrorMessage, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (acquireAccessTokenResult.Success == InteractiveResult.Cancel)
                    {
                        return;
                    }

                    TokenResponse tokenResponse = acquireAccessTokenResult.Token;

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV2, Resources.None, textBox_Page06_ClientID.Text, textBox_Page06_ClientSecret.Text, textBox_Page06_Scopes.Text, textBox_Page06_RedirectUri.Text, textBox_Page06_TenantName.Text);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show(string.Join(Environment.NewLine, validateResult.ErrorMessage), "Office365APIEditor");
                }

                break;

            case PageIndex.Page07_V2MobileAppOptionForm:
                // Option form for V2 auth endpoint Web App

                V2MobileAppUtil v2MobileAppUtil = new V2MobileAppUtil()
                {
                    TenantName  = textBox_Page07_TenantName.Text,
                    ClientID    = textBox_Page07_ClientID.Text,
                    RedirectUri = textBox_Page07_RedirectUri.Text,
                    Scopes      = textBox_Page07_Scopes.Text
                };

                validateResult = v2MobileAppUtil.Validate();

                if (validateResult.IsValid)
                {
                    acquireAccessTokenResult = v2MobileAppUtil.AcquireAccessToken();

                    if (acquireAccessTokenResult.Success == InteractiveResult.Fail)
                    {
                        MessageBox.Show(acquireAccessTokenResult.ErrorMessage, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (acquireAccessTokenResult.Success == InteractiveResult.Cancel)
                    {
                        return;
                    }

                    TokenResponse tokenResponse = acquireAccessTokenResult.Token;

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV2, Resources.None, textBox_Page07_ClientID.Text, "", textBox_Page07_Scopes.Text, textBox_Page07_RedirectUri.Text, textBox_Page07_TenantName.Text);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show(string.Join(Environment.NewLine, validateResult.ErrorMessage), "Office365APIEditor");
                }

                break;

            case PageIndex.Page08_V1AppOnlyByKeyOptionForm:
                // Option form for V1 auth endpoint Web App App only token by Key

                if (ValidateV1WebAppAppOnlyByKeyParam())
                {
                    TokenResponse tokenResponse = AcquireV1WebAppAppOnlyAccessTokenByKey();

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV1, Util.ConvertResourceNameToResourceEnum(comboBox_Page08_Resource.SelectedItem.ToString()), textBox_Page08_ClientID.Text, "", "", "");
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }

                break;

            case PageIndex.Page09_V1AdminConsentOptionForm:
                // Option form for V1 Admin Consent

                if (ValidateV1AdminConsentParam())
                {
                    string authorizationCode = AcquireV1AdminConsentAuthorizationCode();

                    if (authorizationCode == "")
                    {
                        return;
                    }

                    SaveSettings();
                    MessageBox.Show("Admin Consent completed.", "Office365APIEditor");
                }
                break;

            case PageIndex.Page10_BuiltInAppOrBasicAuthSelection:
                // Mode selection page for built-in app or basic auth.

                if (radioButton_Page10_BuiltInApp.Checked)
                {
                    // Built-in app
                    // Go to the next page.
                    ShowPage(PageIndex.Page11_BuiltInAppOptionForm);
                }
                else
                {
                    // Basic auth
                    clientInfo   = new ClientInformation(new TokenResponse(), AuthEndpoints.Basic, Resources.None, "", "", "", "");
                    DialogResult = DialogResult.OK;
                    Close();
                }
                break;

            case PageIndex.Page11_BuiltInAppOptionForm:
                // Option form for the built-in app.

                V2MobileAppUtil builtInAppUtil = new V2MobileAppUtil()
                {
                    ClientID    = Properties.Settings.Default.BuiltInAppClientId,
                    RedirectUri = Properties.Settings.Default.BuiltInAppRedirectUri,
                    Scopes      = textBox_Page11_Scopes.Text,
                    TenantName  = "common"
                };

                validateResult = builtInAppUtil.Validate();

                if (validateResult.IsValid)
                {
                    acquireAccessTokenResult = builtInAppUtil.AcquireAccessToken();

                    if (acquireAccessTokenResult.Success == InteractiveResult.Fail)
                    {
                        MessageBox.Show(acquireAccessTokenResult.ErrorMessage, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (acquireAccessTokenResult.Success == InteractiveResult.Cancel)
                    {
                        return;
                    }

                    TokenResponse tokenResponse = acquireAccessTokenResult.Token;

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV2, Resources.None, Properties.Settings.Default.BuiltInAppClientId, "", textBox_Page11_Scopes.Text, Properties.Settings.Default.BuiltInAppRedirectUri);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show(string.Join(Environment.NewLine, validateResult.ErrorMessage), "Office365APIEditor");
                }

                break;

            case PageIndex.Page12_V2AppOnlyByPasswordForMicrosoftGraphOptionForm:
                // Option form for V2 auth endpoint Web App App only token by password for Microsoft Graph

                if (ValidateV2WebAppAppOnlyByPasswordForMicrosoftGraphParam())
                {
                    TokenResponse tokenResponse = AcquireV2WebAppAppOnlyAccessTokenByPasswordForMicrosoftGraph();

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV2, Resources.Graph, textBox_Page12_ClientId.Text, textBox_Page12_ClientSecret.Text, textBox_Page12_Scopes.Text, "");
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }

                break;

            case PageIndex.Page13_V2AdminConsentOptionForm:
                // Option form for V2 Admin Consent

                if (ValidateV2AdminConsentParam())
                {
                    string authorizationCode = AcquireV2AdminConsentAuthorizationCode();

                    if (authorizationCode == "")
                    {
                        return;
                    }

                    SaveSettings();
                    MessageBox.Show("Admin Consent completed.", "Office365APIEditor");
                }

                break;

            case PageIndex.Page14_SharePointOnlineAppOnlyOptionForm:
                // Option form for the SharePoint Online App-Only REST API Microsoft Azure Access Control Service application.

                if (ValidateSharePointOnlineAppOnlyByKeyParam())
                {
                    TokenResponse tokenResponse = AcquireSharePointOnlineAppOnlyAccessTokenByKey();

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV1, Resources.None, textBox_Page14_ClientID.Text, "", "", "");
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }

                break;

            case PageIndex.None:
            default:
                break;
            }

            button_Back.Enabled = true;
        }
Ejemplo n.º 2
0
        public DialogResult ShowDialog(out ClientInformation ClientInfo)
        {
            DialogResult dialogResult = this.ShowDialog();

            // Build return values.
            // Those values are used to acquire another access token.

            TokenResponse AccessToken;
            string        Resource;
            string        ClientID;
            string        ClientSecret;
            string        Scopes;
            string        RedirectUri;
            bool          UseV2Endpoint;

            AuthEndpoints authEndpoint = new AuthEndpoints();

            if (_tokenResponse.access_token == null && _tokenResponse.id_token != null)
            {
                // Using OpenID Connect
                _tokenResponse.access_token = _tokenResponse.id_token;
            }

            AccessToken = _tokenResponse;

            if (radioButton_WebApp.Checked)
            {
                Resource      = _resource;
                ClientID      = textBox_WebAppClientID.Text;
                ClientSecret  = textBox_WebAppClientSecret.Text;
                Scopes        = "";
                RedirectUri   = "";
                UseV2Endpoint = false;

                authEndpoint = AuthEndpoints.OAuthV1;
            }
            else if (radioButton_NativeApp.Checked)
            {
                Resource      = _resource;
                ClientID      = "";
                ClientSecret  = "";
                Scopes        = "";
                RedirectUri   = "";
                UseV2Endpoint = false;

                authEndpoint = AuthEndpoints.OAuthV1;
            }
            else if (radioButton_V2MobileApp.Checked)
            {
                Resource      = "";
                ClientID      = textBox_V2MobileAppClientID.Text;
                ClientSecret  = "";
                Scopes        = textBox_V2MobileAppScopes.Text;
                RedirectUri   = textBox_V2MobileAppRedirectUri.Text;
                UseV2Endpoint = true;

                authEndpoint = AuthEndpoints.OAuthV2;
            }
            else if (radioButton_V2WebApp.Checked)
            {
                Resource      = "";
                ClientID      = textBox_V2WebAppClientID.Text;
                ClientSecret  = textBox_V2WebAppClientSecret.Text;
                Scopes        = textBox_V2WebAppScopes.Text;
                RedirectUri   = textBox_V2WebAppRedirectUri.Text;
                UseV2Endpoint = true;

                authEndpoint = AuthEndpoints.OAuthV2;
            }
            else
            {
                Resource      = "";
                ClientID      = "";
                ClientSecret  = "";
                Scopes        = "";
                RedirectUri   = "";
                UseV2Endpoint = false;

                authEndpoint = AuthEndpoints.Basic;
            }

            Resources resource = new Resources();

            if (Resource == "Exchange Online")
            {
                resource = Resources.Outlook;
            }
            else if (Resource == "Microsoft Graph")
            {
                resource = Resources.Graph;
            }
            else if (Resource == "Office 365 Management API")
            {
                resource = Resources.Management;
            }
            else
            {
                resource = Resources.None;
            }

            ClientInformation result = new ClientInformation(AccessToken, authEndpoint, resource, ClientID, ClientSecret, Scopes, RedirectUri);

            ClientInfo = result;
            return(dialogResult);
        }
Ejemplo n.º 3
0
        private void button_Next_Click(object sender, EventArgs e)
        {
            switch (currentPageIndex)
            {
            case PageIndex.Page00_PortalSelection:
                // Portal selection page

                if (radioButton_Page00_MicrosoftAzurePortal.Checked)
                {
                    // V1 endpoint
                    // Go to the next page.
                    ShowPage(PageIndex.Page01_MicrosoftAzurePortalAppSelection);
                }
                else if (radioButton_Page00_AppRegistrationPortal.Checked)
                {
                    // V2 endpoint
                    // Go to the next page.
                    ShowPage(PageIndex.Page02_AppRegistrationPortalAppSelection);
                }
                else
                {
                    // Create a return value and close this window.
                    clientInfo   = new ClientInformation(new TokenResponse(), AuthEndpoints.Basic, Resources.None, "", "", "", "");
                    DialogResult = DialogResult.OK;
                    Close();
                }

                break;

            case PageIndex.Page01_MicrosoftAzurePortalAppSelection:
                // App selection page for V1 auth endpoint.

                if (radioButton_Page01_V1Web.Checked)
                {
                    // V1 endpoint Web App
                    // Go to the next page.
                    ShowPage(PageIndex.Page03_V1WebAppOptionForm);
                }
                else if (radioButton_Page01_V1Native.Checked)
                {
                    // V1 endpoint Native App
                    // Go to the next page.
                    ShowPage(PageIndex.Page04_V1NativeAppOptionForm);
                }
                else if (radioButton_Page01_V1AppOnlyByCert.Checked)
                {
                    // V1 endpoint Web App (App Only Token by certificate)
                    // Go to the next page.
                    ShowPage(PageIndex.Page05_V1AppOnlyByCertOptionForm);
                }
                else if (radioButton_Page01_V1AppOnlyByKey.Checked)
                {
                    // V1 endpoint Web App (App Only Token by Key)
                    // Go to the next page.
                    ShowPage(PageIndex.Page08_V1AppOnlyByKeyOptionForm);
                }
                else
                {
                    // V1 endpoint Admin Consent
                    // Go to the next page.
                    ShowPage(PageIndex.Page09_V1AdminConsentOptionForm);
                }

                break;

            case PageIndex.Page02_AppRegistrationPortalAppSelection:
                // App selection page for V2 auth endpoint.

                if (radioButton_Page02_V2Web.Checked)
                {
                    // V2 endpoint Web App
                    // Go to the next page.
                    ShowPage(PageIndex.Page06_V2WebAppOptionForm);
                }
                else
                {
                    // V2 endpoint Mobile App
                    // Go to the next page.
                    ShowPage(PageIndex.Page07_V2MobileAppOptionForm);
                }

                break;

            case PageIndex.Page03_V1WebAppOptionForm:
                // Option form for V1 auth endpoint Web App

                if (ValidateV1WebAppParam())
                {
                    string authorizationCode = AcquireV1WebAppAuthorizationCode();

                    if (authorizationCode == "")
                    {
                        return;
                    }

                    TokenResponse tokenResponse = AcquireV1WebAppAccessToken(authorizationCode);

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV1, Util.ConvertResourceNameToResourceEnum(comboBox_Page03_Resource.SelectedItem.ToString()), textBox_Page03_ClientID.Text, textBox_Page03_ClientSecret.Text, "", textBox_Page03_RedirectUri.Text);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }

                break;

            case PageIndex.Page04_V1NativeAppOptionForm:
                // Option form for V1 auth endpoint Native App

                if (ValidateV1NativeAppParam())
                {
                    string authorizationCode = AcquireV1NativeAppAuthorizationCode();

                    if (authorizationCode == "")
                    {
                        return;
                    }

                    TokenResponse tokenResponse = AcquireV1NativeAppAccessToken(authorizationCode);

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV1, Util.ConvertResourceNameToResourceEnum(comboBox_Page04_Resource.SelectedItem.ToString()), textBox_Page04_ClientID.Text, "", "", textBox_Page04_RedirectUri.Text);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }

                break;

            case PageIndex.Page05_V1AppOnlyByCertOptionForm:
                // Option form for V1 auth endpoint Web App App only token by certificate

                if (ValidateV1WebAppAppOnlyByCertParam())
                {
                    TokenResponse tokenResponse = AcquireV1WebAppAppOnlyAccessTokenByCert();

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV1, Util.ConvertResourceNameToResourceEnum(comboBox_Page05_Resource.SelectedText), textBox_Page05_ClientID.Text, "", "", "");
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }

                break;

            case PageIndex.Page06_V2WebAppOptionForm:
                // Option form for V2 auth endpoint Web App

                if (ValidateV2WebAppParam())
                {
                    string authorizationCode = AcquireV2WebAppAuthorizationCode();

                    if (authorizationCode == "")
                    {
                        return;
                    }

                    TokenResponse tokenResponse = AcquireV2WebAppAccessToken(authorizationCode);

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV2, Resources.None, textBox_Page06_ClientID.Text, textBox_Page06_ClientSecret.Text, textBox_Page06_Scopes.Text, textBox_Page06_RedirectUri.Text);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }

                break;

            case PageIndex.Page07_V2MobileAppOptionForm:
                // Option form for V2 auth endpoint Web App

                if (ValidateV2MobileAppParam())
                {
                    string authorizationCode = AcquireV2MobileAppAuthorizationCode();

                    if (authorizationCode == "")
                    {
                        return;
                    }

                    TokenResponse tokenResponse = AcquireV2MobileAppAccessToken(authorizationCode);

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV2, Resources.None, textBox_Page07_ClientID.Text, "", textBox_Page07_Scopes.Text, textBox_Page07_RedirectUri.Text);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }

                break;

            case PageIndex.Page08_V1AppOnlyByKeyOptionForm:
                // Option form for V1 auth endpoint Web App App only token by Key

                if (ValidateV1WebAppAppOnlyByKeyParam())
                {
                    TokenResponse tokenResponse = AcquireV1WebAppAppOnlyAccessTokenByKey();

                    if (tokenResponse != null)
                    {
                        SaveSettings();

                        // Create a return value and close this window.
                        clientInfo   = new ClientInformation(tokenResponse, AuthEndpoints.OAuthV1, Util.ConvertResourceNameToResourceEnum(comboBox_Page08_Resource.SelectedText), textBox_Page08_ClientID.Text, "", "", "");
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }

                break;

            case PageIndex.Page09_V1AdminConsentOptionForm:
                // Option form for V1 Admin Consent

                if (ValidateV1AdminConsentParam())
                {
                    string authorizationCode = AcquireV1AdminConsentAuthorizationCode();

                    if (authorizationCode == "")
                    {
                        return;
                    }

                    SaveSettings();
                    MessageBox.Show("Admin Consent completed.", "Office365APIEditor");
                }
                break;

            case PageIndex.None:
            default:
                break;
            }

            button_Back.Enabled = true;
        }
Ejemplo n.º 4
0
        private void newAccessTokenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClientInformation newClientInfo;

            AccessTokenWizard accessTokenWizard = new AccessTokenWizard();

            if (accessTokenWizard.ShowDialog(out newClientInfo) == DialogResult.OK)
            {
                // Override current info.
                clientInfo = newClientInfo;

                if (clientInfo.AuthType == AuthEndpoints.Basic)
                {
                    // Basic auth

                    useBasicAuth = true;
                    textBox_BasicAuthSMTPAddress.Enabled            = true;
                    textBox_BasicAuthSMTPAddress.Text               = "";
                    textBox_BasicAuthPassword.Enabled               = true;
                    textBox_BasicAuthPassword.Text                  = "";
                    textBox_BasicAuthPassword.UseSystemPasswordChar = true;
                }
                else if (clientInfo.AuthType == AuthEndpoints.OAuthV1)
                {
                    // OAuth V1

                    useBasicAuth = false;
                    textBox_BasicAuthSMTPAddress.Enabled            = false;
                    textBox_BasicAuthSMTPAddress.Text               = "OAuth (V1 Endpoint)";
                    textBox_BasicAuthPassword.Enabled               = false;
                    textBox_BasicAuthPassword.Text                  = "OAuth (V1 Endpoint)";
                    textBox_BasicAuthPassword.UseSystemPasswordChar = false;
                }
                else
                {
                    // OAuth V2

                    useBasicAuth = false;
                    textBox_BasicAuthSMTPAddress.Enabled            = false;
                    textBox_BasicAuthSMTPAddress.Text               = "OAuth (V2 Endpoint)";
                    textBox_BasicAuthPassword.Enabled               = false;
                    textBox_BasicAuthPassword.Text                  = "OAuth (V2 Endpoint)";
                    textBox_BasicAuthPassword.UseSystemPasswordChar = false;
                }



                _tokenResponse = clientInfo.Token;
                _resource      = clientInfo.ResourceUri;
                _clientID      = clientInfo.ClientID;
                _clientSecret  = clientInfo.ClientSecret;
                _scopes        = clientInfo.Scopes;
                _redirectUri   = clientInfo.RedirectUri;
                _useV2Endpoint = (clientInfo.AuthType == AuthEndpoints.OAuthV2);

                button_ViewTokenInfo.Enabled = !string.IsNullOrEmpty(clientInfo.Token.access_token);
                button_RefreshToken.Enabled  = !string.IsNullOrEmpty(clientInfo.Token.refresh_token);
                button_Run.Enabled           = true;

                // Select the Body page.
                tabControl_HeadersAndBody.SelectTab(1);
            }

            //AcquireAccessToken();
        }