There is no public API available to register OAuth consumer key with Jazz application. The only workaround I found so far would be to use undocumented admin services REST API.
A new consumer key can be registered using the following URI:
http(s)://server:port/<context>/service/com.ibm.team.repository.service.internal.oauth.IOAuthRestService/registerNewConsumer
This service accepts four parameters (URL-encoded):
name – consumer key name;
consumerKey – consumer key unique ID (It is optional parameter, and the key will be generated by the application is missing);
consumerSecret – consumer secret object;
secretType – usually ‘STRING’.
Perl code sample:
use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Headers;
...
my $app = 'https://server:port/context';
my $oauth_register = 'service/com.ibm.team.repository.service.internal.oauth.IOAuthRestService/registerNewConsumer';
# Create user agent
my $ua = LWP::UserAgent->new( cookie_jar => {}, default_headers => HTTP::Headers->new( Accept => 'text/xml'));
# login to the CLM application
...
# set referrer header
$ua->default_header('Referer' => "$app/admin");
# Register consumer key with provided id
my $response = $ua->request( POST "$app/$oauth_register",
[
consumerSecret => 'secret',
secretType => 'STRING',
name => 'key name',
consumerKey => 'key id'
]
);
Allow consumer key id to be generated by the server.
my $response = $ua->request( POST "$app/$oauth_register",
[
consumerSecret => 'secret',
secretType => 'STRING',
name => 'key name'
]
);
# check response
if($response->code() != 200){
print $response->content() . "\n";
die "Cannot create consumer key\n Message: " . $response->message() . "\n";
}
# get consumer key value
if( $response->content() !~ /\<value\>([^\<]+)\<\/value\>/ ){
die "Cannot find consumer key value in registration response\n";
}
my $oauth_id = $1;
print "Consumer key id = $oauth_id\n"
In order to set consumer key properties or assign specific user id to the key, the following service could be used:
http(s)://server:port/<context>/service/com.ibm.team.repository.service.internal.oauth.IOAuthRestService/setConsumerAttributes
Perl sample:
my $oauth_setattrs = 'service/com.ibm.team.repository.service.internal.oauth.IOAuthRestService/setConsumerAttributes';
...
# update consumer attributes
$response = $ua->request( POST "$app/$oauth_setattrs",
[
consumerKey => $oauth_id,
trusted => 'true',
userId => 'desirable_user_id'
]
);
These services are not documented, but I did not find a better way to automate consumer creation task so far. I was able to use it with CLM 3.x, 4.x, and 5.x applications.
Pingback: Creating CLM Application Friend from Script | Pavel Dubovitsky
A very useful post, thanks