Web Connection
Integrating UserSecurity with a REST process
Gravatar is a globally recognized avatar based on your email address. Integrating UserSecurity with a REST process
  Richard Kaye
  All
  Oct 25, 2023 @ 06:21am

Hi Rick,

Silly question time again. As I make more progress with my REST application project, I am starting to think about how to make sure it only accepts requests from authorized user(s). As I am not presenting any login/out UI, am I right in concluding that I don't really need to add this as a process class, or add any script mapping? IOW I can just add the necessary prgs to my project, then instantiate a usersecurity object and call the necessary methods, etc in the context of my REST requests. Obviously, I have to make sure everything is properly decoupled from any FE.

Thanks!

Gravatar is a globally recognized avatar based on your email address. re: Integrating UserSecurity with a REST process
  Rick Strahl
  Richard Kaye
  Oct 25, 2023 @ 02:13pm

No the separate process class is merely for administration and optionally for handling authentication separately.

For a REST Service you wouldn't be using any of that - you'd only use the class directly to do the authentication and user lookup.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Integrating UserSecurity with a REST process
  Richard Kaye
  Rick Strahl
  Oct 26, 2023 @ 04:18am

Thanks. That's what I thought but it's good to have that confirmed.

Gravatar is a globally recognized avatar based on your email address. re: Integrating UserSecurity with a REST process
  Richard Kaye
  Rick Strahl
  Oct 26, 2023 @ 08:14am

Ok, that's working out pretty well. Next question: I assume it's better to have the auth credentials set as a header in the request as opposed to params on the URL, correct? And I can use Request.GetExtraHeader to retrieve the auth credentials.

Gravatar is a globally recognized avatar based on your email address. re: Integrating UserSecurity with a REST process
  Richard Kaye
  Rick Strahl
  Oct 26, 2023 @ 09:35am

I'm also thinking I need to override the wwprocess.authenticate method?

Gravatar is a globally recognized avatar based on your email address. re: Integrating UserSecurity with a REST process
  Rick Strahl
  Richard Kaye
  Oct 26, 2023 @ 09:58am

... only if you need to change the functionality. If you're using default authentication you don't have to change anything.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Integrating UserSecurity with a REST process
  Richard Kaye
  Rick Strahl
  Oct 26, 2023 @ 11:40am

Sorry for all the n00b questions. I tend to think out loud while working thorough this sort of stuff. Authenticate is overloaded. I figured out I have to instantiate my security object in the process OnInit and then call its authenticate method instead of the process' authenticate method. Another step forward.

Next thing to figure out; how to get a 401 into the response when the auth fails. I just tried populating ErrorMessage but there must be more. 😃

Gravatar is a globally recognized avatar based on your email address. re: Integrating UserSecurity with a REST process
  Rick Strahl
  Richard Kaye
  Oct 26, 2023 @ 12:19pm

Add:

Response.Status = "401 Unauthorized"

in your request anywhere before the response is sent out.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Integrating UserSecurity with a REST process
  Richard Kaye
  Rick Strahl
  Oct 26, 2023 @ 12:35pm

I used this:

RETURN this.ErrorResponse([Access denied],[401 Access Denied])  

Works fine.

I may want to book a little time, probably next week depending on your availability, to review my overall approach with you before I open this up to my internal audience just to make sure I'm following best practices. I have to say I'm having fun figuring out how to do this.

Gravatar is a globally recognized avatar based on your email address. re: Integrating UserSecurity with a REST process
  Rick Strahl
  Richard Kaye
  Oct 26, 2023 @ 05:03pm

The status message generally is UnAuthorized not Access Denied. You can put that in the body but the status message should probably be proper...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Integrating UserSecurity with a REST process
  Richard Kaye
  Rick Strahl
  Oct 27, 2023 @ 01:51am

Thanks! I'll update that text.

© 1996-2024