Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change unauthorized error 401 with Rest API #20

Closed
jawharOmar opened this issue Aug 27, 2017 · 15 comments
Closed

Change unauthorized error 401 with Rest API #20

jawharOmar opened this issue Aug 27, 2017 · 15 comments

Comments

@jawharOmar
Copy link

Hi guys your help please

I tried to connect to openKM via Rest API but i have problem when i send request to check login credential and username i get error 401 back and this error is handing by browser and some boring window will appear i want change this error from source code to send back another error number instate of error 401 to prevent browser to show this window , could you please help me how can I do that inside source code ?

@vohoailen
Copy link

You can check the login method on class com.openkm.rest.endpoint.AuthService to debug and customize the response for login API.

@jawharOmar
Copy link
Author

Dear Vohoailen thanks so much for your reply
could you please help me more now i am on the class which you told be but i do not know how can i change it , this is the code
.........
@get
@path("/login")
public void login() throws GenericException {
try {
log.debug("login()");
AuthModule am = ModuleManager.getAuthModule();
am.login();
log.debug("login: void");
} catch (Exception e) {
throw new GenericException(e);
}
}
.....................

@darkman97i
Copy link
Contributor

Rest goes with "basic" authentication and error 401 is right you will not be able to change it from source code, because really your call not arrive to the method code.

Login method really it is not for login, this method must be used when users had never logged from the UI. I will try to explain, when you login from UI - first time - are done some special task by the repository ( create user trash, etc... ). Unfortunately when you are accessing exclusively from API these task are not done, and that's the reason why we created login method ( in this scenario should be executed at least one time ). Might be login method name cause some confusion, because this is not really for login, is for something what happens first time you have been logged.

@jawharOmar
Copy link
Author

Thanks Dear Darkman97i for your reply

Login method really it is not for login
then what should i do to prevent browser to not show browser default login window ( i think the only way is by change return status to some thing else instate of 401 ) is there any way to do this in source code or some where else ?

@darkman97i
Copy link
Contributor

Should be changed the basic authentication for other, for example based in token or try to get both working together. What is the problem for you with basic authentication ( browser asking for user and password ? ) ?

@jawharOmar
Copy link
Author

( browser asking for user and password ? ) ?
yes exactly , when i send User name and password via post request from Javascript in case user name and password is not right browser show "Browser Basic Authentication pop window "
a windows like this
https://www.google.com/search?q=Browser+Basic+Authentication+pop&client=ubuntu&hs=e8L&channel=fs&source=lnms&tbm=isch&sa=X&ved=0ahUKEwj-uKT_-_nVAhVGBBoKHc_qBCwQ_AUIDCgD&biw=1321&bih=671#imgrc=p9Sllo1AlfQb9M:

@darkman97i
Copy link
Contributor

Is not a problem with basic authentication, you are doing bad javascript call. Take a look at this javascript project what connects to OpenKM with javascript https://github.com/darkman97i/kamify/blob/master/js/download.js

@jawharOmar
Copy link
Author

Dear Darkman thanks so much I do not know how can I appreciate your help
let me try , I used Angular-4 as font-end I will try to solve this
this was my scenario

because OKM using basic authentication I will try to get user name and password from user then make AJAX call to ( openKM/services/rest/login ) if i get HTTP status OK like (204) then I will store this user name and password from client side to future Request , then i will drive user to another page to make further request , i made call ( openKM/services/rest ) just for test if this user name and password is right but unfortunately it made this big problem for me .

@darkman97i
Copy link
Contributor

I do not know why are you using javascript, why do not try to integrate SDK for JAVA, https://docs.openkm.com/kcenter/view/sdk4j-1.1/ with your own authentication provider ?

@jawharOmar
Copy link
Author

Dear Mr. Darkman thanks a lot to your reply yes it is interested why I do not using SDK I will go along with SDK , but this will not make any problem for me like some thing can be done with RESR API can not be done with SDK ?

@darkman97i
Copy link
Contributor

darkman97i commented Aug 31, 2017

OpenKM SDK is a wrapper client for REST webservices. All API REST methods are available from SDK ( if you find some method available from REST not exposed across SDK might be bug ).

@jawharOmar
Copy link
Author

Dears
could you please tell me why i can not download the SDK
when i click on the link i will get not found error
image

@darkman97i
Copy link
Contributor

Try again please, because today we have been moving the maven to another server and might have been some issues with it ( the dns change might need 24 hours to be propagated, if in 24 hours the error persist tell us ).

@jawharOmar
Copy link
Author

Dear Darkman from previous comment you said

OpenKM SDK is a wrapper client for REST webservices. All API REST methods are available from SDK
as i see from Rest API there is some method for (create user,delete user,create role,... ) but from java SDK i can not see this functionality
https://www.openkm.com/wiki/index.php/SDK_for_Java_1.1#Auth
image

@darkman97i
Copy link
Contributor

Last question, it does not have any relation with the issue I will proceed closing it. If you want to discuss about new feature etc... , please do from our public forum at https://forum.openkm.com/viewforum.php?f=31 ( Auth API is not all exposed with webservices, if you want to collaborate on extending it, tell us and we'll try to give you the clues for it ). This is the actual existing class for it, what should be extended https://github.com/openkm/document-management-system/blob/6.3-DEV/src/main/java/com/openkm/ws/endpoint/AuthService.java ( us we can suggest you how doing it ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants