/// <summary>
///     Create the JiraApi, using OAuth 1 for the communication, here the HttpClient is configured
/// </summary>
/// <param name="baseUri">Base URL, e.g. https://yourjiraserver</param>
/// <param name="jiraOAuthSettings">JiraOAuthSettings</param>
/// <param name="httpSettings">IHttpSettings or null for default</param>
        public static IJiraClient Create(Uri baseUri, JiraOAuthSettings jiraOAuthSettings, IHttpSettings httpSettings = null)
        {
            JiraClient client       = new JiraClient(baseUri, httpSettings);
            var        jiraOAuthUri = client.JiraBaseUri.AppendSegments("plugins", "servlet", "oauth");

            var oAuthSettings = new OAuth1Settings
            {
                TokenUrl          = jiraOAuthUri.AppendSegments("request-token"),
                TokenMethod       = HttpMethod.Post,
                AccessTokenUrl    = jiraOAuthUri.AppendSegments("access-token"),
                AccessTokenMethod = HttpMethod.Post,
                CheckVerifier     = false,
                SignatureType     = OAuth1SignatureTypes.RsaSha1,
                Token             = jiraOAuthSettings.Token,
                ClientId          = jiraOAuthSettings.ConsumerKey,
                CloudServiceName  = jiraOAuthSettings.CloudServiceName,
                RsaSha1Provider   = jiraOAuthSettings.RsaSha1Provider,
                AuthorizeMode     = jiraOAuthSettings.AuthorizeMode,
                AuthorizationUri  = jiraOAuthUri.AppendSegments("authorize")
                                    .ExtendQuery(new Dictionary <string, string>
                {
                    { OAuth1Parameters.Token.EnumValueOf(), "{RequestToken}" },
                    { OAuth1Parameters.Callback.EnumValueOf(), "{RedirectUrl}" }
                })
            };

            // Configure the OAuth1Settings

            client.Behaviour = client.ConfigureBehaviour(OAuth1HttpBehaviourFactory.Create(oAuthSettings), httpSettings);
            return(client);
        }
Beispiel #2
0
        public OAuthTests(ITestOutputHelper testOutputHelper)
        {
            // A demo Private key, to create a RSACryptoServiceProvider.
            // This was created from a .pem via a tool here http://www.jensign.com/opensslkey/index.html
            const string privateKeyXml = @"<RSAKeyValue><Modulus>tGIwsCH2KKa6vxUDupW92rF68S5SRbgr7Yp0xeadBsb0BruTt4GMrVL7QtiZWM8qUkY1ccMa7LkXD93uuNUnQEsH65s8ryID9P
DeEtCBcxFEZFdcKfyKR+5B+NRLW5lJq10sHzWbJ0EROUmEjoYfi3CtsMkJHYHDL9dZeCqAZHM=</Modulus><Exponent>AQAB</Exponent><P>14DdDg26
CrLhAFQIQLT1KrKVPYr0Wusi2ovZApz2/RnM7a7CWUJuDR3ClW5g9hdi+KQ0ceD5oJYX5Vexv2uk+w==</P><Q>1kfU0+DkXc6I/jXHJ6pDLA5s7dBHzWgDs
BzplSdkVQbKT3MbeYjeByOxzXhulOWLBQW/vxmW4HwU95KTRlj06Q==</Q><DP>SPoBYY3yb0cN/J94P/lHgJMDCNkyUEuJ/PoYndLrrN/8zow8kh91xwlJ6
HJ9cTiQMmTgwaOOxPuu0eI1df4M2w==</DP><DQ>klJaspRPXP877NssM5nAZMU0/O/NGCZ+3jPgDUno6WbJn5cqm8MqWhW1xGkImgRk+fkDBquiq4gPiT89
8jusgQ==</DQ><InverseQ>d5Zrr6Q8AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54Lw03eHTNQghS0A==</Inverse
Q><D>WFlbZXlM2r5G6z48tE+RTKLvB1/btgAtq8vLw/5e3KnnbcDD6fZO07m4DRaPjRryrJdsp8qazmUdcY0O1oK4FQfpprknDjP+R1XHhbhkQ4WEwjmxPst
ZMUZaDWF58d3otc23mCzwh3YcUWFu09KnMpzZsK59OfyjtkS44EDWpbE=</D></RSAKeyValue>";

            // Create the RSACryptoServiceProvider for the XML above
            var rsaCryptoServiceProvider = new RSACryptoServiceProvider();

            rsaCryptoServiceProvider.FromXmlString(privateKeyXml);

            // Configure the XUnitLogger for logging
            LogSettings.RegisterDefaultLogger <XUnitLogger>(LogLevels.Verbose, testOutputHelper);

            // Only a few settings for the Jira OAuth are important
            var oAuthSettings = new JiraOAuthSettings
            {
                // Is specified on the linked-applications as consumer key
                ConsumerKey = "lInXLgx6HbF9FFq1ZQN8iSEnhzO3JVuf",
                // This needs to have the private key, the represented public key is set in the linked-applications
                RsaSha1Provider = rsaCryptoServiceProvider,
                // Use a server at Localhost to redirect to, alternative an embedded browser can be used
                AuthorizeMode = AuthorizeModes.LocalhostServer,
                // When using the embbed browser this is directly visible, with the LocalhostServer it's in the info notice after a redirect
                CloudServiceName = "Greenshot Jira",
                // the IOAuth1Token implementation, here it's this, gets the tokens to store & retrieve for later
                Token = this
            };

            // Create the JiraApi for the Uri and the settings
            _jiraApi = OAuthJiraClient.Create(TestJiraUri, oAuthSettings);
        }
Beispiel #3
0
		public JiraOAuthTests(ITestOutputHelper testOutputHelper)
		{
			// A demo Private key, to create a RSACryptoServiceProvider.
			// This was created from a .pem via a tool here http://www.jensign.com/opensslkey/index.html
			const string privateKeyXml = @"<RSAKeyValue><Modulus>tGIwsCH2KKa6vxUDupW92rF68S5SRbgr7Yp0xeadBsb0BruTt4GMrVL7QtiZWM8qUkY1ccMa7LkXD93uuNUnQEsH65s8ryID9P
DeEtCBcxFEZFdcKfyKR+5B+NRLW5lJq10sHzWbJ0EROUmEjoYfi3CtsMkJHYHDL9dZeCqAZHM=</Modulus><Exponent>AQAB</Exponent><P>14DdDg26
CrLhAFQIQLT1KrKVPYr0Wusi2ovZApz2/RnM7a7CWUJuDR3ClW5g9hdi+KQ0ceD5oJYX5Vexv2uk+w==</P><Q>1kfU0+DkXc6I/jXHJ6pDLA5s7dBHzWgDs
BzplSdkVQbKT3MbeYjeByOxzXhulOWLBQW/vxmW4HwU95KTRlj06Q==</Q><DP>SPoBYY3yb0cN/J94P/lHgJMDCNkyUEuJ/PoYndLrrN/8zow8kh91xwlJ6
HJ9cTiQMmTgwaOOxPuu0eI1df4M2w==</DP><DQ>klJaspRPXP877NssM5nAZMU0/O/NGCZ+3jPgDUno6WbJn5cqm8MqWhW1xGkImgRk+fkDBquiq4gPiT89
8jusgQ==</DQ><InverseQ>d5Zrr6Q8AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54Lw03eHTNQghS0A==</Inverse
Q><D>WFlbZXlM2r5G6z48tE+RTKLvB1/btgAtq8vLw/5e3KnnbcDD6fZO07m4DRaPjRryrJdsp8qazmUdcY0O1oK4FQfpprknDjP+R1XHhbhkQ4WEwjmxPst
ZMUZaDWF58d3otc23mCzwh3YcUWFu09KnMpzZsK59OfyjtkS44EDWpbE=</D></RSAKeyValue>";

			// Create the RSACryptoServiceProvider for the XML above
			var rsaCryptoServiceProvider = new RSACryptoServiceProvider();
			rsaCryptoServiceProvider.FromXmlString(privateKeyXml);

			// Configure the XUnitLogger for logging
			LogSettings.RegisterDefaultLogger<XUnitLogger>(LogLevels.Verbose, testOutputHelper);

			// Only a few settings for the Jira OAuth are important
			var oAuthSettings = new JiraOAuthSettings
			{
				// Is specified on the linked-applications as consumer key
				ConsumerKey = "lInXLgx6HbF9FFq1ZQN8iSEnhzO3JVuf",
				// This needs to have the private key, the represented public key is set in the linked-applications
				RsaSha1Provider = rsaCryptoServiceProvider,
				// Use a server at Localhost to redirect to, alternative an embedded browser can be used
				AuthorizeMode = AuthorizeModes.LocalhostServer,
				// When using the embbed browser this is directly visible, with the LocalhostServer it's in the info notice after a redirect
				CloudServiceName = "Greenshot Jira",
				// the IOAuth1Token implementation, here it's this, gets the tokens to store & retrieve for later
				Token = this
			};
			// Create the JiraApi for the Uri and the settings
			_jiraApi = new JiraApi(TestJiraUri, oAuthSettings);
		}