Skip to Main Content

ORDS, SODA & JSON in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

401--Unauthorized error when try to get access token

Hi,

I got 401--Unauthorized error when try to get access token,

regarding to the following document,I executed the required steps:

https://docs.oracle.com/cd/E56351_01/doc.30/e87809/developing-REST-applications.htm#AELIG90132

3.3.5 Tutorial: Protecting and Accessing Resources

===1. Enable the schema

SQL> conn ordstest/ordstest

Connected.

SQL> begin

  2    ords.enable_schema;

  commit;

end;  3    4

  5

  6

  7

  8  /

PL/SQL procedure successfully completed.

===2. Create a resource

SQL> begin

  2  ords.create_service(

      p_module_name => 'examples.employees' ,

      p_base_path  => '/examples/employees/',

      p_pattern =>  '.' ,

      p_items_per_page => 7,

      p_source  =>  'select * from emp order by empno desc');

commit;

end;  3    4    5    6    7    8    9

10  /

PL/SQL procedure successfully completed.

and I can get expected result with the command

curl -i -k -1 --tlsv1 https://celvpvm04540.us.oracle.com:7002/apex/ordstest/examples/employees/

===3. Create a privilege

SQL> begin

  2    ords.create_role('HR Administrator');

  ords.create_privilege(

      p_name => 'example.employees',

      p_role_name => 'HR Administrator',

      p_label => 'Employee Data',

      p_description => 'Provide access to employee HR data');

  commit;

end;  3    4    5    6    7    8    9   10

11  /

PL/SQL procedure successfully completed.

SQL> select id,name from user_ords_privileges where name = 'example.employees';

        ID

----------

NAME

--------------------------------------------------------------------------------

     10090

example.employees

  

===4. Associate the privilege with resources

SQL> begin

  2   ords.create_privilege_mapping(

      p_privilege_name => 'example.employees',

      p_pattern => '/examples/employees/*');

  commit;

end;  3    4    5    6

  7  /

PL/SQL procedure successfully completed.

SQL> select privilege_id, name, pattern from user_ords_privilege_mappings;

PRIVILEGE_ID

------------

NAME

--------------------------------------------------------------------------------

PATTERN

--------------------------------------------------------------------------------

       10090

example.employees

/examples/employees/*

       10083

oracle.soda.privilege.developer

/soda/*

PRIVILEGE_ID

------------

NAME

--------------------------------------------------------------------------------

PATTERN

--------------------------------------------------------------------------------

also I got the expected 401 error

curl -i -k -1 --tlsv1 https://celvpvm04540.us.oracle.com:7002/apex/ordstest/examples/employees/

===5. Register the OAuth client

SQL> SQL>

SQL> begin

  2   oauth.create_client(

      p_name => 'Client Credentials Example',

      p_grant_type => 'client_credentials',

      p_privilege_names => 'example.employees',

      p_support_email => 'support@example.com');

commit;

end;  3    4    5    6    7    8

  9  /

PL/SQL procedure successfully completed.

SQL> select client_id,client_secret from user_ords_clients where name = 'Client Credentials Example';

CLIENT_ID                        CLIENT_SECRET

-------------------------------- --------------------------------

TzrNVXKEE_W3M7XXA8UJdQ..         tXVslONXKMZISOIW5QqWoA..

===6. Grant the OAuth client a required role

SQL> begin

  2   oauth.grant_client_role(

     'Client Credentials Example',

     'HR Administrator');

commit;

end;  3    4    5    6

  7  /

PL/SQL procedure successfully completed.

SQL> ^C

SQL>

SQL> select * from user_ords_client_roles where client_name = 'Client Credentials Example';

CLIENT_ID

----------

CLIENT_NAME

--------------------------------------------------------------------------------

   ROLE_ID

----------

ROLE_NAME

--------------------------------------------------------------------------------

     10093

Client Credentials Example

     10089

HR Administrator

then when I try to get access token it still returned 401 error

-bash-4.2$ curl -i -k -1 --tlsv1 --user clientId:clientSecret -d "grant_type=client_credentials" https://celvpvm04540.us.oracle.com:7002/apex/ordstest/oauth/token

HTTP/1.1 401 Unauthorized

Date: Thu, 04 Jan 2018 07:01:55 GMT

Content-Length: 1468

Content-Type: text/html; charset=UTF-8

WWW-Authenticate: Basic realm="weblogic"

Could anyone kindly advise me?

Regards

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2018
Added on Jan 4 2018
0 comments
1,004 views