deepgram / dgmrcp

UniMRCP server plugin for Deepgram Brain
Apache License 2.0
11 stars 13 forks source link

Unauthorized Error #94

Closed Bunoviske closed 1 year ago

Bunoviske commented 2 years ago

Hello,

I am receiving the following Unauthorized Error when I run ./unimrcpserver:

2022-03-31 19:21:29:698917 [INFO]   Assign Control Channel <17555ce6a6134930@speechrecog> to Connection 10.148.16.121:1544 <-> 10.148.16.103:38084 [0] -> [1]
2022-03-31 19:21:29:698959 [INFO]   Process RECOGNIZE Request <17555ce6a6134930@speechrecog> [1]
2022-03-31 19:21:29:699157 [NOTICE] [DG :: dgmrcp::channel] Channel::recognize
2022-03-31 19:21:29:699209 [NOTICE] [DG :: dgmrcp::channel] Building request to wss://brain.deepgram.com/v2/listen/stream?endpointing=true&interim_results=true&encoding=linear16&sample_rate=8000&channels=1&language=de-DE
2022-03-31 19:21:29:699262 [NOTICE] [DG :: dgmrcp::channel] handled RECOGNIZE request
2022-03-31 19:21:29:699294 [INFO]   Process RECOGNIZE Response <17555ce6a6134930@speechrecog> [1]
2022-03-31 19:21:29:699298 [INFO]   State Transition IDLE -> RECOGNIZING <17555ce6a6134930@speechrecog>
2022-03-31 19:21:29:699434 [NOTICE] [DG :: dgmrcp::channel] Opening websocket connection
2022-03-31 19:21:29:699577 [INFO]   Send MRCPv2 Data 10.148.16.121:1544 <-> 10.148.16.103:38084 [83 bytes]
MRCP/2.0 83 1 200 IN-PROGRESS
Channel-Identifier: 17555ce6a6134930@speechrecog

2022-03-31 19:21:29:862074 [INFO]   [DG :: rustls::client::hs] No cached session for DNSNameRef("brain.deepgram.com")
2022-03-31 19:21:29:862128 [INFO]   [DG :: rustls::client::hs] Not resuming any session
2022-03-31 19:21:30:017187 [INFO]   [DG :: rustls::client::hs] Using ciphersuite TLS13_AES_256_GCM_SHA384
2022-03-31 19:21:30:017686 [INFO]   [DG :: rustls::client::tls13] Not resuming
2022-03-31 19:21:30:017877 [INFO]   [DG :: rustls::client::tls13] TLS1.3 encrypted extensions: [ServerNameAck]
2022-03-31 19:21:30:017923 [INFO]   [DG :: rustls::client::hs] ALPN protocol is None
2022-03-31 19:21:30:331582 [INFO]   [DG :: rustls::client::tls13] Ticket saved
2022-03-31 19:21:30:331638 [INFO]   [DG :: rustls::client::tls13] Ticket saved
2022-03-31 19:21:30:573510 [ERROR]  [DG :: dgmrcp::channel] Failed to open WebSocket connection: HTTP error: 401 Unauthorized
2022-03-31 19:21:30:573557 [INFO]   [DG :: dgmrcp::channel] send recognition complete
2022-03-31 19:21:30:573689 [INFO]   Process RECOGNITION-COMPLETE Event <17555ce6a6134930@speechrecog> [1]
2022-03-31 19:21:30:573722 [INFO]   State Transition RECOGNIZING -> RECOGNIZED <17555ce6a6134930@speechrecog>
2022-03-31 19:21:30:573855 [INFO]   Send MRCPv2 Data 10.148.16.121:1544 <-> 10.148.16.103:38084 [206 bytes]
MRCP/2.0 206 RECOGNITION-COMPLETE 1 COMPLETE
Channel-Identifier: 17555ce6a6134930@speechrecog
Completion-Cause: 006 recognizer-error
Completion-Reason: Check that credentials are properly configured.

I configured the plugin-factory like this:

<engine id="Deepgram" name="libdgmrcp" enable="true">  
        <param name="brain_url" value="wss://brain.deepgram.com/v2/"/>  
        <param name="brain_username" value="bruno@email.com"/>  
        <param name="brain_password" value="mypassword"/>  
        <param name="language" value="de"/>  
</engine>

Is there any issue? I tried using my API Key as well but it did not work.

Thanks, Bruno

adeschamps commented 2 years ago

Hi Bruno,

As a quick check, can you confirm that your credentials work with our HTTP API? For example, you could try this endpoint to list the available models:

curl -u bruno@email.com:mypassword https://brain.deepgram.com/v2/models

At a glance, your config looks valid, so if the above works but the MRCP plugin doesn't, then we may have a trickier issue.

Bunoviske commented 2 years ago

Hello Anthony,

I tried what you suggested and I received this:

{
"error":"Unauthorized",
"reason":"No information available.",
"transaction_key":"dD+Rm7umV2YgvqEkOhLokQxLoqsng0cMkDDnuxHm0rGam5rTg7p1g1GoVjlxMynOvsQ7NAJG93Ymup0Btjw4crN3uUeC47np3GxVq0us/am/4gMcxGv/Lk8U+1XrGNuyTBHWx+TmnMxtXNGq9jAWA/LolcBz+pVAJiGJ4vE4",
"request_id":"m0rJtFo0D0wclLlaP49ekWPsD8FlUHYb"
}

It works If I use my API key on this url: https://api.deepgram.com/v1/. For example, I could get all my projects running:

curl --request GET \
  --url https://api.deepgram.com/v1/projects \
  --header 'Authorization: Token <YOUR_DEEPGRAM_API_KEY>' \
  --header 'content-type: application/json'
adeschamps commented 2 years ago

Oh! This makes sense now. Deepgram recently launched a new version of the API, at https://api.deepgram.com/v1/ (which is what everything at https://console.deepgram.com refers to) and we're gradually migrating users away from https://brain.deepgram.com/v2. (Don't let the /v1 and /v2 fool you -- it's a new domain, so we started the version number over again).

The WebSocket protocol is identical, so things should generally work the same way, but one thing that did change is auth. The old API is expecting a header that looks like Authorization: Basic $(user:pass | base64) whereas the new API expects Authorization: Token $API_KEY. This repo hasn't been updated to work with the new auth.

The code that handles this is at https://github.com/deepgram/dgmrcp/blob/4a0d45baa4034a373b2850dccf13b04931e1ecb7/src/channel.rs#L339-L342 and https://github.com/deepgram/dgmrcp/blob/4a0d45baa4034a373b2850dccf13b04931e1ecb7/src/channel.rs#L356-L361. PR's are welcome, of course, if you need this change to unblock your work! Otherwise, we'll make sure it's on our todo list.

Bunoviske commented 2 years ago

I changed the URL to the new API, that is the new error (404 Not Found):

2022-04-01 22:42:47:341517 [INFO]   Process RECOGNIZE Request <eb8f400e7a4f4b53@speechrecog> [2]
2022-04-01 22:42:47:341553 [NOTICE] [DG :: dgmrcp::channel] Channel::recognize
2022-04-01 22:42:47:341604 [NOTICE] [DG :: dgmrcp::channel] Building request to wss://api.deepgram.com/v1/listen/stream?endpointing=true&interim_results=true&encoding=linear16&sample_rate=8000&channels=1&language=de
2022-04-01 22:42:47:341720 [NOTICE] [DG :: dgmrcp::channel] Opening websocket connection
2022-04-01 22:42:47:341828 [NOTICE] [DG :: dgmrcp::channel] handled RECOGNIZE request
2022-04-01 22:42:47:341856 [INFO]   Process RECOGNIZE Response <eb8f400e7a4f4b53@speechrecog> [2]
2022-04-01 22:42:47:341863 [INFO]   State Transition IDLE -> RECOGNIZING <eb8f400e7a4f4b53@speechrecog>
2022-04-01 22:42:47:341890 [INFO]   Send MRCPv2 Data 10.148.16.121:1544 <-> 10.148.16.121:47774 [83 bytes]
MRCP/2.0 83 2 200 IN-PROGRESS
Channel-Identifier: eb8f400e7a4f4b53@speechrecog

2022-04-01 22:42:47:512300 [INFO]   [DG :: rustls::client::hs] No cached session for DNSNameRef("api.deepgram.com")
2022-04-01 22:42:47:512444 [INFO]   [DG :: rustls::client::hs] Not resuming any session
2022-04-01 22:42:47:672933 [INFO]   [DG :: rustls::client::hs] Using ciphersuite TLS13_CHACHA20_POLY1305_SHA256
2022-04-01 22:42:47:673351 [INFO]   [DG :: rustls::client::tls13] Not resuming
2022-04-01 22:42:47:673452 [INFO]   [DG :: rustls::client::tls13] TLS1.3 encrypted extensions: []
2022-04-01 22:42:47:673471 [INFO]   [DG :: rustls::client::hs] ALPN protocol is None
2022-04-01 22:42:47:675188 [INFO]   [DG :: rustls::client::tls13] Ticket saved
2022-04-01 22:42:47:989329 [ERROR]  [DG :: dgmrcp::channel] Failed to open WebSocket connection: HTTP error: 404 Not Found
2022-04-01 22:42:47:989515 [INFO]   [DG :: dgmrcp::channel] send recognition complete
2022-04-01 22:42:47:989650 [INFO]   Process RECOGNITION-COMPLETE Event <eb8f400e7a4f4b53@speechrecog> [2]
2022-04-01 22:42:47:989667 [INFO]   State Transition RECOGNIZING -> RECOGNIZED <eb8f400e7a4f4b53@speechrecog>
2022-04-01 22:42:47:989710 [INFO]   Send MRCPv2 Data 10.148.16.121:1544 <-> 10.148.16.121:47774 [239 bytes]
MRCP/2.0 239 RECOGNITION-COMPLETE 2 COMPLETE
Channel-Identifier: eb8f400e7a4f4b53@speechrecog
Completion-Cause: 006 recognizer-error
Completion-Reason: Check that credentials are properly configured and the requested model is valid.
adeschamps commented 2 years ago

I missed this before, but the other difference between the APIs is the path -- the old API uses /listen/stream whereas the new API just uses /listen (docs).

This is hardcoded at https://github.com/deepgram/dgmrcp/blob/4a0d45baa4034a373b2850dccf13b04931e1ecb7/src/channel.rs#L883 -- changing that line to just .join("listen") should fix it.

Thanks for bearing with me here -- this MRCP plugin predates the new API, and we're still in the transition phase between the old and the new APIs.

Bunoviske commented 2 years ago

Uhuuuu! It worked, that is nice. I integrated with Asterisk, looks pretty good. I had never seen a rust code before and I wasn't very interested in learning it, so excuse me any redundancy in the code. I will create the PR next week, enjoy the weekend ;)