lynndylanhurley / devise_token_auth

Token based authentication for Rails JSON APIs. Designed to work with jToker and ng-token-auth.
Do What The F*ck You Want To Public License
3.54k stars 1.13k forks source link

No header for username with dash #1279

Open Herz3h opened 5 years ago

Herz3h commented 5 years ago
    def update_auth_header
        # cannot save object if model has invalid params
        return unless @resource && @resource.valid? && @client_id

        # Generate new client_id with existing authentication
        @client_id = nil unless @used_auth_by_token

        if @used_auth_by_token && !DeviseTokenAuth.change_headers_on_each_request
            # should not append auth header if @resource related token was
            # cleared by sign out in the meantime
            return if @resource.reload.tokens[@client_id].nil?

            auth_header = @resource.build_auth_header(@token, @client_id)

            # update the response header
            response.headers.merge!(auth_header)

        else

            # Lock the user record during any auth_header updates to ensure
            # we don't have write contention from multiple threads
            @resource.with_lock do
                # should not append auth header if @resource related token was
                # cleared by sign out in the meantime
                return if @used_auth_by_token && @resource.tokens[@client_id].nil?

                # determine batch request status after request processing, in case
                # another processes has updated it during that processing
                @is_batch_request = is_batch_request?(@resource, @client_id)

                auth_header = {}

                # extend expiration of batch buffer to account for the duration of
                # this request
                if @is_batch_request
                    auth_header = @resource.extend_batch_buffer(@token, @client_id)

                    response.headers.merge!(auth_header)
                    # update Authorization response header with new token
                else
                    auth_header = @resource.create_new_auth_token(@client_id)

                    # update the response header
                    response.headers.merge!(auth_header)
                end

            end # end lock

        end

    end

Above code was change from this commit

Now if you create a username with a dash, for instance: my-username

The API does not return uid/accessToken/client headers.

MaicolBen commented 5 years ago

That's an old version but I don't think we changed anything related to that in recent versions. I am not following your error, where do we look for the username in that method? Was the user registered correctly?