Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9107781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:39:20+00:00 2026-06-17T02:39:20+00:00

I have REST service requirements in which some calls require authentication and some don’t.

  • 0

I have REST service requirements in which some calls require authentication and some don’t. Absolutely no state is used, as the calls are all independent from one another. I have put something together which seems to work, but is this the right way to go about not using sessions?

This question is kind of related to my WCF question which is answered here.

Firstly I registered the authentication method:

        Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                                    new IAuthProvider[] {
                                        new CustomCredentialsAuthProvider(), //HTML Form post of UserName/Password credentials
                                    }
                        ));

I then attribute the respective calls (or service or DTO) with the Authenticate attribute:

[Authenticate]
public HelloResponse Post(Hello request)
{
    return new HelloResponse { Result = "Hello, " + request.Name  + " with POST & Auth"};
}

I inherit from the BasicAuthProvider class which does the authentication:

public class CustomCredentialsAuthProvider : BasicAuthProvider
{
    public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
    {
        return userName == "dylan" && password == "abc123";
    }

    public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
    {
        session.IsAuthenticated = true;

        //Important: You need to save the session!
         authService.SaveSession(session, new TimeSpan(0,0,10)); 
    }
}

As you can see, I do save the session but it times out after 10 seconds. This is the part that I’m sure can potentially be done better. It seems to work nicely though.

Is there a better way of doing what I’m trying to accomplish?
Is there also any way, due to the sessionless nature of these services, to remove the Auth, AssignRoles and UnassignRoles methods?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:39:21+00:00Added an answer on June 17, 2026 at 2:39 am

    If you wanted to keep using ServiceStack’s Authentication and Session support you could just add a response filter that clears the user session after the service is executed, e.g:

    this.ResponseFilters.Add((req, res, dto) => req.RemoveSession());
    

    Basically after each request is executed it clears the session, so no record of them having authenticated exists.

    Otherwise you can just skip using ServiceStack’s Authentication completely and just provide your own via RequestFitlers of FilterAttributes (which is essentially what SS Auth does under the hood).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a REST service for which I have a WADL file. I want
So I have wcf rest service which succesfuly runs from a console app, if
I have a REST web service which exposes 2 methods- [POST method] Client will
I have a REST service that I would like to require client certificates. The
I have WCF rest service returning XML/RSS feeds. Some methods return data contracts, some
I have a C# WCF REST Service which allows the addition of a bookmark,
I have a REST service which takes JSON and XML as input and does
I have a REST service which takes a JSON request. I want to validate
I have a REST service that returns a JSON like this: [{@id:123,name:Name}] and I'm
I have a REST service consumed by a .Net WCF client. When an error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.