Web service "Authorization required" error

Moderator: crythias

Post Reply
ExecMike
Znuny newbie
Posts: 7
Joined: 27 Mar 2017, 09:20
Znuny Version: 5.0.16
Real Name: Mike

Web service "Authorization required" error

Post by ExecMike »

Hello OTRS masters

It's my first post here so hello to everyone who brings an added value to this forum.

Currently I'm trying to implement the Web Service in my OTRS. The goal is to have 3rd party systems to create a new tickets in OTRS.

I created the Web Service entry in OTRS GUI (I used GenericTicketConnectorSOAP.yml) from github)
I also put the otrs.SOAPRequest.pl on my server (I took it from OTRS website). I modified the perl script with appropriate username and password to my OTRS.

When I run the otrs.SOAPRequest.pl from my OTRS server it returns "401 Authorization Required at otrs.SOAPRequest.pl line 73". The line 73 is

Code: Select all

my $SOAPObject = SOAP::Lite->uri($NameSpace)->proxy($URL)
I think it's because Namespace is "http://www.otrs.org/TicketConnector/" and my OTRS does not have access to the Internet. However I'm not sure what should I put in namespace instead of this to make it works.

I will appreciate any help from you.

Code: Select all

#!/usr/bin/perl -w
# --
# otrs.SOAPRequest.pl - sample to send a SOAP request to OTRS Generic Interface Ticket Connector
# Copyright (C) 2001-2013 xxx, http://otrs.com/
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --

use strict;
use warnings;

# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);

use SOAP::Lite;
use Data::Dumper;

# ---
# Variables to be defined.

# this is the URL for the web service
# the format is
# <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl/Webservice/<WEB_SERVICE_NAME>
# or
# <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl/WebserviceID/<WEB_SERVICE_ID>
my $URL = 'http://localhost/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector';

# this name space should match the specified name space in the SOAP transport for the web service.
my $NameSpace = 'http://www.otrs.org/TicketConnector/';

# this is operation to execute, it could be TicketCreate, TicketUpdate, TicketGet, TicketSearch
# or SessionCreate. and they must to be defined in the web service.
my $Operation = 'TicketCreate';

# this variable is used to store all the parameters to be included on a request in XML format. Each
# operation has a determined set of mandatory and non mandatory parameters to work correctly. Please
# check the OTRS Admin Manual in order to get a complete list of parameters.
my $XMLData = '
<UserLogin>some user login</UserLogin>
<Password>some password</Password>
<Ticket>
    <Title>some title</Title>
    <CustomerUser>some customer user login</CustomerUser>
    <Queue>some queue</Queue>
    <State>some state</State>
    <Priority>some priority</Priority>
</Ticket>
<Article>
    <Subject>some subject</Subject>
    <Body>some body</Body>
    <ContentType>text/plain; charset=utf8</ContentType>
</Article>
';

# ---

# create a SOAP::Lite data structure from the provided XML data structure.
my $SOAPData = SOAP::Data
    ->type( 'xml' => $XMLData );

my $SOAPObject = SOAP::Lite
    ->uri($NameSpace)
    ->proxy($URL)
    ->$Operation($SOAPData);

# check for a fault in the soap code.
if ( $SOAPObject->fault ) {
    print $SOAPObject->faultcode, " ", $SOAPObject->faultstring, "\n";
}

# otherwise print the results.
else {

    # get the XML response part from the SOAP message.
    my $XMLResponse = $SOAPObject->context()->transport()->proxy()->http_response()->content();

    # deserialize response (convert it into a perl structure).
    my $Deserialized = eval {
        SOAP::Deserializer->deserialize($XMLResponse);
    };

    # remove all the headers and other not needed parts of the SOAP message.
    my $Body = $Deserialized->body();

    # just output relevant data and no the operation name key (like TicketCreateResponse).
    for my $ResponseKey ( keys %{$Body} ) {
        print Dumper( $Body->{$ResponseKey} );
    }
}
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Web service "Authorization required" error

Post by jojo »

You have to change

Code: Select all

<UserLogin>some user login</UserLogin>
<Password>some password</Password>
to match your system...
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
ExecMike
Znuny newbie
Posts: 7
Joined: 27 Mar 2017, 09:20
Znuny Version: 5.0.16
Real Name: Mike

Re: Web service "Authorization required" error

Post by ExecMike »

Hello jojo

Thank you for your prompt reply. As I have already mentioned I modified the perl script (otrs.SOAPRequest) with appropriate username and password to my OTRS. I have already tried with two different accounts with full rights in the OTRS.

So you mean that Namespace can be still pointing at: "http://www.otrs.org/TicketConnector/" even if the server does not have access to the Internet?

Thank you in advance for any further replies.
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Web service "Authorization required" error

Post by jojo »

no internet connection is needed for the namespace..
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
ExecMike
Znuny newbie
Posts: 7
Joined: 27 Mar 2017, 09:20
Znuny Version: 5.0.16
Real Name: Mike

Re: Web service "Authorization required" error

Post by ExecMike »

Ok. Thanks for clarification. As I said I put the correct username and password (checked couple times) into the SOAPRequest script.

For testing purposes I ran SOAPRequest.pl directly from OTRS server and still getting authorization error. Should I somehow create a Session using "SessionCreate" Web service module or it should just work as it is?
Do you have any other thoughts what can be a source of 401 Authorization error? I would like to mention that there is Kerberos authentication for SSO configured but I think it should not have impact in my scenario.

Thank you for your ongoing support.
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Web service "Authorization required" error

Post by jojo »

ExecMike wrote: Do you have any other thoughts what can be a source of 401 Authorization error? I would like to mention that there is Kerberos authentication for SSO configured but I think it should not have impact in my scenario.
It would... So it should be on a different URL without Kerberos
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
ExecMike
Znuny newbie
Posts: 7
Joined: 27 Mar 2017, 09:20
Znuny Version: 5.0.16
Real Name: Mike

Re: Web service "Authorization required" error

Post by ExecMike »

Thank you jojo

I have tested this on diffrerent OTRS without Keberos enabled and there was no authorization error.
Sorry for maybe stupid question but by this you mean that if OTRS uses Kerberos authentication webservice TicketCreate functionality cannot be used?
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Web service "Authorization required" error

Post by jojo »

if you manage to have the script using a kerberos ticket it can work. but most likely you have to configure apache in a way that no kerberos is used for the generic interface
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
ExecMike
Znuny newbie
Posts: 7
Joined: 27 Mar 2017, 09:20
Znuny Version: 5.0.16
Real Name: Mike

Re: Web service "Authorization required" error

Post by ExecMike »

Helo jojo

Thank you. It was very helpful.
Post Reply