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

  • Home
  • SEARCH
  • 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 8996217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:43:30+00:00 2026-06-15T23:43:30+00:00

By default, ServiceStack returns http status 401 when I try to call anything before

  • 0

By default, ServiceStack returns http status 401 when I try to call anything before authorization.
How do I return http status 200 and my DTO instead of that?

Ideally, I want to show boolean NeedAuth=true flag in ResponseStatus application wide, if I try calling anything unauthorized.

  • 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-15T23:43:30+00:00Added an answer on June 15, 2026 at 11:43 pm

    I’ve modified my previously created custom AuthProvider.
    Now if I call anything before authentication or try to provide wrong credentials, I get HTTP 200 OK status and this response:

    {
        "NeedAuth": true
    }
    

    I’ve extended AuthResponse:

    public class MyAuthResponse : AuthResponse
    {
        public bool? NeedAuth { get; set; }
    }
    

    And modified my custom AuthProvider inherited from CredentialsAuthProvider:

    // This one is called when I call anything before authorization
    public override void OnFailedAuthentication(IAuthSession session, ServiceStack.ServiceHost.IHttpRequest httpReq, ServiceStack.ServiceHost.IHttpResponse httpRes)
    {
        httpRes.StatusCode = (int)HttpStatusCode.OK;
        var callback = httpReq.GetJsonpCallback();
        var doJsonp = EndpointHost.Config.AllowJsonpRequests && !string.IsNullOrEmpty(callback);
        var res = new MyAuthResponse() { NeedAuth = true };
        if (doJsonp)
            httpRes.WriteToResponse(httpReq, res, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
        else
            httpRes.WriteToResponse(httpReq, res);
    }
    
    // This one is called when I try to login
    public override object Authenticate(IServiceBase authService, IAuthSession session, Auth request)
    {
        var userName = request.UserName;
        var password = request.Password;
        var res = new MyAuthResponse();
    
        if (!LoginMatchesSession(session, userName))
        {
            authService.RemoveSession();
            session = authService.GetSession();
        }
    
        if (TryAuthenticate(authService, userName, password))
        {
            if (session.UserAuthName == null)
                session.UserAuthName = userName;
    
            OnAuthenticated(authService, session, null, null);
    
            res.UserName = userName;
            res.SessionId = session.Id;
        }
        else
            res.NeedAuth = true;
    
        return res;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

default SBT log level is info (see http://code.google.com/p/simple-build-tool/wiki/RunningSbt ). How do I set it
default condition alt text http://shup.com/Shup/330969/1104593215-My-Desktop.png After clicking on Sitemap link How to write HTML
By default my script is accessible by using this url http://localhost/myscript/public/ . But i
I've setup a site using http://razor.servicestack.net/ . I've created several views and matching services
Default wp_list_authors will return authors list in the following format: <a href=#>AuthorName</a> (PostCount) I
Default django cache keys generator: def make_key(key, key_prefix, version): return ':'.join([key_prefix, str(version), key]) I
I would like to set ServiceStack's default format to JSON, as opposed to the
I'm trying to use ServiceStack REST DTO and OrmLite with monoDroid. But I can't
By default, Laravel's raw query methods return results as arrays of stdClass objects: Array
Default JVM uses maximum 1.5 GB RAM/JVM Java application. But my Server have 8

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.