Chan_sip.c:26179 handle_request_invite: Failed to authenticate device

I am new to asterisk. My internal call i.e. extensions to extension is working but when I call outside it is not going

This error means a wrong password was supplied on the originating leg of the call, although there simply is nothing like enough information to provide any more guidance than this. (Note, if the call originated from outside, service providers generally don’t authenticate themselves. See remotescret for one sided authentication.)

Also note that, if you are a new user, chan_sip has a reduced level of support (although this is a configuration error not a bug). Unless there is an overriding need to use it, you use pjsip, instead.

Actually I am making a call to a person outside. It’s not a incoming call

You will have to provide the sip debugging to be sure, but a call from a directly attached device will fail with this error before Asterisk has even looked at the number being dialled.

<------------->
— (12 headers 0 lines) —
Really destroying SIP dialog ‘239ec743598a8b7f44ca8e835be553ed@10.0.0.5:5060’ Method: OPTIONS

<— SIP read from UDP:10.1.7.20:30990 —>
SUBSCRIBE sip:1020@10.0.0.5 SIP/2.0
Via: SIP/2.0/UDP 10.1.7.20:30990;branch=z9hG4bK-d8754z-434ed232db11097f-1—d8754z-;rport
Max-Forwards: 70
Contact: sip:1020@10.1.7.20:30990
To: "1020"sip:1020@10.0.0.5
From: "1020"sip:1020@10.0.0.5;tag=9f310968
Call-ID: NWU0ZDYwYTUxNDg5NWE3MzIwMzYwMDFjYjA1OTBmYTI.
CSeq: 1 SUBSCRIBE
Expires: 300
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
User-Agent: eyeBeam release 1102u stamp 52345
Event: message-summary
Content-Length: 0

<------------->
— (13 headers 0 lines) —
Sending to 10.1.7.20:30990 (NAT)
Creating new subscription
Sending to 10.1.7.20:30990 (NAT)
sip_route_dump: route/path hop: sip:1020@10.1.7.20:30990
Found peer ‘1020’ for ‘1020’ from 10.1.7.20:30990

<— Transmitting (no NAT) to 10.1.7.20:30990 —>
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.1.7.20:30990;branch=z9hG4bK-d8754z-434ed232db11097f-1—d8754z-;received=10.1.7.20;rport=30990
From: "1020"sip:1020@10.0.0.5;tag=9f310968
To: "1020"sip:1020@10.0.0.5;tag=as3f45d289
Call-ID: NWU0ZDYwYTUxNDg5NWE3MzIwMzYwMDFjYjA1OTBmYTI.
CSeq: 1 SUBSCRIBE
Server: FPBX-13.0.192.8(13.14.0)
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm=“asterisk”, nonce="07331a8e"
Content-Length: 0

<------------>
Scheduling destruction of SIP dialog ‘NWU0ZDYwYTUxNDg5NWE3MzIwMzYwMDFjYjA1OTBmYTI.’ in 6528 ms (Method: SUBSCRIBE)

<— SIP read from UDP:10.1.7.20:30990 —>
SUBSCRIBE sip:1020@10.0.0.5 SIP/2.0
Via: SIP/2.0/UDP 10.1.7.20:30990;branch=z9hG4bK-d8754z-c524372c9e645854-1—d8754z-;rport
Max-Forwards: 70
Contact: sip:1020@10.1.7.20:30990
To: "1020"sip:1020@10.0.0.5
From: “1020"sip:1020@10.0.0.5;tag=9f310968
Call-ID: NWU0ZDYwYTUxNDg5NWE3MzIwMzYwMDFjYjA1OTBmYTI.
CSeq: 2 SUBSCRIBE
Expires: 300
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
User-Agent: eyeBeam release 1102u stamp 52345
Authorization: Digest username=“1020”,realm=“asterisk”,nonce=“07331a8e”,uri="sip:1020@10.0.0.5”,response=“94d77ac60c164a94016549e1221d7404”,algorithm=MD5
Event: message-summary
Content-Length: 0

<------------->
— (14 headers 0 lines) —
Creating new subscription
Sending to 10.1.7.20:30990 (no NAT)
Found peer ‘1020’ for ‘1020’ from 10.1.7.20:30990

<— Transmitting (no NAT) to 10.1.7.20:30990 —>
SIP/2.0 404 Not found (no mailbox)
Via: SIP/2.0/UDP 10.1.7.20:30990;branch=z9hG4bK-d8754z-c524372c9e645854-1—d8754z-;received=10.1.7.20;rport=30990
From: "1020"sip:1020@10.0.0.5;tag=9f310968
To: "1020"sip:1020@10.0.0.5;tag=as3f45d289
Call-ID: NWU0ZDYwYTUxNDg5NWE3MzIwMzYwMDFjYjA1OTBmYTI.
CSeq: 2 SUBSCRIBE
Server: FPBX-13.0.192.8(13.14.0)
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0

<------------>
[2017-06-07 15:12:03] NOTICE[31276]: chan_sip.c:28276 handle_request_subscribe: Received SIP subscribe for peer without mailbox: 1020
Really destroying SIP dialog ‘NWU0ZDYwYTUxNDg5NWE3MzIwMzYwMDFjYjA1OTBmYTI.’ Method: SUBSCRIBE

<— SIP read from UDP:10.1.7.20:30990 —>

<------------->

Here are the messages when I open sip debug on. Can you make out something from here ?

Nothing useful there, only the subscribe request from 1020 to asterisk not a call attempt.

Also you have not marked it as pre-formatted text, so important information is being treated as markup, and lost.