Search code examples
javaandroidauthenticationazure-active-directorymicrosoft-translator

Microsoft Azure Translation API authentication methods


I'm trying to set up Microsoft Translation API (part of MS Cognitive Services) in my Android app (using Java). I'm relatively new to Android programming and authentication methods, and I'm a bit confused with the those ones.

When I registered for an Azure account I created an Azure Directory, then created an Android App in the portal, configured it and got my auth_config.json .

Well, when I checked the MS translator API docs I saw that I can use it through a GET request and the API key provided. But also I saw I can authenticate by using a token, and that's where I'm stuck.

I've searching for days and I cannot find a clear and concise tutorial/guide/docs to Authenticate (no user context) from my Android app in order to use MS translate API by using tokens.

I found this link but it's only applicable when users have to sign in.

Any help related to auth tokens flow and conceptual design of them is also welcomed, but the main question would be "How to authenticate an Android App (no user context) by using tokens for accessing an Azure API?"

Thanks.


Solution

  • It sounds like you are trying to create a native Android Application using Java to get an access token in order to utilize the MS Translator API. But you would like to flow to be non-interactive.

    You shouldn't need to get an access token in order to utilize the MS Translator API. Per the documentation you will only need to get the translator keys and then you will be able to use the Translator REST API using the Translator key.

    The Translator Getting Started on how to setup and get keys can be found here : https://learn.microsoft.com/en-us/azure/cognitive-services/translator/translator-text-how-to-signup And the documentation on how to use the Translator API in Java can be found here : https://learn.microsoft.com/en-ca/azure/cognitive-services/translator/quickstart-java-translate

    In addition to that, I think it's important to understand the concepts of how to get access tokens from Microsoft for the future. The v2.0(also referred to as converged) endpoint flows and explanation on how the authentication process works can be found here under "concepts > authentication > OAuth2 .... flow". https://learn.microsoft.com/en-us/azure/active-directory/develop/authentication-scenarios

    That being said, the MSAL library doesn't necessarily have all these flows implemented yet. To see more information on what MSAL libraries support what auth flows, you can find this information at the link here : https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows

    Unfortunately we don't support the non-interactive flow using the MSAL Android library yet. If you're interested in this feature please submit an issue against the MSAL Android Library here : https://github.com/AzureAD/microsoft-authentication-library-for-android/issues And one of the engineers that handles the library will reach out and discuss it further.

    All the Azure AD libraries have wikis that can be found on their respective github repos. The MSAL Android one can be found here : https://github.com/AzureAD/microsoft-authentication-library-for-android/wiki

    Hopefully this has been helpful, and if you have anymore questions please leave a comment.

    Essentially you won't need to use MSAL and you should be able to just use the translator key to make calls to the MS Translator API.