Is there a way to tell, programmatically, if azcopy login or azcopy logout has been previously run on this machine? I'd like to know if it's going to use OAuth authentication or something else when I go to transfer a file.
I looked in the c:\users\<username>\.azcopy directory but there wasn't anything that looked like a token.
Hi @Hong-Revo, thanks for reaching out!
I'll discuss your suggestion with the team.
This would be a useful feature. I need to know if the consumer is logged into azcopy before attempting any operations, so that I can ask them to login.
Hi @ollieatkinson, could you please elaborate a bit on your use case? Do you need to know any other information? I.e. is a simple "yes" enough or do you need to know more about how the user is logged in?
Hi @ollieatkinson, could you please elaborate a bit on your use case? Do you need to know any other information? I.e. is a simple "yes" enough or do you need to know more about how the user is logged in?
A simple yes or no answer would suffice, I am including it as a step in a Makefile and it would be useful to give a descriptive error (or just ask them to login) if they are not currently signed into the tool.
As long as they are authenticated it's fine to move on.
I am using this workaround until support is added into the tool:
login:
@azcopy list "https://example.core.windows.net/example${AZURE_SAS_TOKEN}" \
| grep "ServiceCode=ResourceNotFound" > /dev/null \
&& open https://microsoft.com/devicelogin \
&& echo "Please login with the code:" \
&& azcopy $@ \
| sed -n "s/.*code \(.*\) to.*$$/\1/p" \
&& echo "Logged in!" \
|| echo "Logged in!"
On Linux we store the logged-in token in the SessionKey ring. If you do keyctl show after logging in you'll see which keyname we use. You can probably just grep the result of keyctl show, for that key-name string.
Note that this doesn't confirm that the token is still valid, but given their relatively long lifetimes, it's reasonably reliable.
Thanks @JohnRusk. We are currently using this for macOS - is the mechanism the same but using the Keychain?
Yes.
Thanks @JohnRusk
security find-generic-password -a AzCopyOAuthTokenCache
login:
@(security find-generic-password -a AzCopyOAuthTokenCache > /dev/null && echo "Logged in!") \
|| \
(open https://microsoft.com/devicelogin && azcopy $@)
Windows version
$isAzCopyLoggedIn = Test-Path "$env:USERPROFILE\.azcopy\accessToken.json" -PathType Leaf
Most helpful comment
A simple yes or no answer would suffice, I am including it as a step in a
Makefileand it would be useful to give a descriptive error (or just ask them to login) if they are not currently signed into the tool.As long as they are authenticated it's fine to move on.