Getting null pointer error while doing Authenticating Bearer Token

@dasniko I have reffer your video regarding Implementing Custom REST Resources (endpoints). while Authenticating the Bearer Token I’m getting null pointer exception.
This is the way to authenticate the Bearer token,

AuthResult authResult = new AppAuthManager.BearerTokenAuthenticator(session).authenticate();

Regards
Sasanka Sekhar

And what exactly is your question?

You just provided one line of sourcecode, without anything else.
Where exactly does the NPE occur? Which object is null (not only the line!)?
How does your request looks like?
…???

I want to Authenticate the bearer token

This is the approach what i taken for authenticate the token for API. While Authenticating the bearer token null pointer exception is coming

Again, you just provided some source code. Not the information I asked for.
No information where exactly the NPE occurs (which object is null), no information about the request you are doing.
Without that, I can’t help, I can only guess, but that’s not my approach to help. So, please provide the proper information. Thanks for you understanding.

Oh right, sorry. The NPE occurs in the line

AuthResult authResult = new AppAuthManager.BearerTokenAuthenticator(session).authenticate();

Although, the session is not null, the autheResult, for some reason, is getting null.

Ok, if authResult is null, the NPE does not occur in the mentioned line, but after that. That’s a big difference, as null is a valid result of checking the authentication!

As you wrote, you are referencing to my code, you should have seen that there is a null-check in my code:

AuthResult is null when there’s no, or a non-valid authorization header provided in your request.

Ok as per your code we went throughly but in session authentication token was available at time of authentication .
code
here i have my token but still getting the error. in authresult.

As per the request i am passing the token which is required to access the admin-cli, but still getting authResult as null.

Then there’s something wrong with your token :man_shrugging:
My code just works fine. You’ll have to debug your environment to find the root cause.