Using TotpSecurityStampBasedTokenProvider for TOTP with Google Authenticator
I'm implementing 2FA using TOTP on my asp.net web api 2 webservice (NOT .net core).
The implementation uses the TotpSecurityStampBasedTokenProvider which is provided by the Microsoft.AspNet.Identity framework.
When looking at Google Authenticator requirements it lists that the secret needs to be a base32 encoded string.
If you look at the code from the TotpSecurityStampBasedTokenProvider it uses the user's SecurityStamp as the secret which is generated by the Identity Framework. This is a GUID and not a base32 encoded string.
According to the specifications for the Google Authenticator there is a requirement that the secret is a base32 encoded string.
How can I use the TotpSecurityStampBasedTokenProvider for use with Google Authenticator?
c# asp.net-identity totp
add a comment |
I'm implementing 2FA using TOTP on my asp.net web api 2 webservice (NOT .net core).
The implementation uses the TotpSecurityStampBasedTokenProvider which is provided by the Microsoft.AspNet.Identity framework.
When looking at Google Authenticator requirements it lists that the secret needs to be a base32 encoded string.
If you look at the code from the TotpSecurityStampBasedTokenProvider it uses the user's SecurityStamp as the secret which is generated by the Identity Framework. This is a GUID and not a base32 encoded string.
According to the specifications for the Google Authenticator there is a requirement that the secret is a base32 encoded string.
How can I use the TotpSecurityStampBasedTokenProvider for use with Google Authenticator?
c# asp.net-identity totp
add a comment |
I'm implementing 2FA using TOTP on my asp.net web api 2 webservice (NOT .net core).
The implementation uses the TotpSecurityStampBasedTokenProvider which is provided by the Microsoft.AspNet.Identity framework.
When looking at Google Authenticator requirements it lists that the secret needs to be a base32 encoded string.
If you look at the code from the TotpSecurityStampBasedTokenProvider it uses the user's SecurityStamp as the secret which is generated by the Identity Framework. This is a GUID and not a base32 encoded string.
According to the specifications for the Google Authenticator there is a requirement that the secret is a base32 encoded string.
How can I use the TotpSecurityStampBasedTokenProvider for use with Google Authenticator?
c# asp.net-identity totp
I'm implementing 2FA using TOTP on my asp.net web api 2 webservice (NOT .net core).
The implementation uses the TotpSecurityStampBasedTokenProvider which is provided by the Microsoft.AspNet.Identity framework.
When looking at Google Authenticator requirements it lists that the secret needs to be a base32 encoded string.
If you look at the code from the TotpSecurityStampBasedTokenProvider it uses the user's SecurityStamp as the secret which is generated by the Identity Framework. This is a GUID and not a base32 encoded string.
According to the specifications for the Google Authenticator there is a requirement that the secret is a base32 encoded string.
How can I use the TotpSecurityStampBasedTokenProvider for use with Google Authenticator?
c# asp.net-identity totp
c# asp.net-identity totp
edited Nov 28 '18 at 9:20
Peter
asked Nov 28 '18 at 9:07
PeterPeter
9,1781461103
9,1781461103
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The TotpSecurityStampBasedTokenProvider uses UserManager.CreateSecurityTokenAsync to generate the secret code which is used to calculate the token.
The code relies on the user ID, and is generated into a byte array, which is usually shown as base-32 or QR code on-screen to the user in the TOTP setup phase.
So long story short, there is nothing to worry about.
Thank you Patrick, can you tell me which method I need to use on the UserManager to get the secret as a byte to encode into base-32 for the setup phase? I was using UserManager.GetSecurityStampAsync but that must be where my implementation is wrong.
– Peter
Nov 28 '18 at 9:42
That would beGetSecurityStampAsyncorCreateSecurityTokenAsyncprobably.
– Patrick Hofman
Nov 28 '18 at 9:45
1
You're right, I was encoding the secret to a byte array using the incorrect encoding . I should use unicode. Thank you for the insight!
– Peter
Nov 28 '18 at 9:50
Yes, indeed. Good you found it.
– Patrick Hofman
Nov 28 '18 at 9:51
1
The sample projects are usually quite useful. See for example here: github.com/aspnet/Identity/blob/master/samples/…
– Patrick Hofman
Nov 28 '18 at 9:51
|
show 1 more comment
The problem is that the TotpSecurityStampBasedTokenProvider provided by Microsoft.AspNet.Identity.Core implements a hardcoded timestep of 3 minutes. Google Authenticator uses a default value of 30 seconds, which can NOT be modified according to the documentation provided.
This causes different codes to be generated by both TOTP computations resulting in an always false authentication.
I have added a ticket to the github repository of aspnet.identity about this.
So for now nothing left for me to do than create my own totpProvider
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53515739%2fusing-totpsecuritystampbasedtokenprovider-for-totp-with-google-authenticator%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The TotpSecurityStampBasedTokenProvider uses UserManager.CreateSecurityTokenAsync to generate the secret code which is used to calculate the token.
The code relies on the user ID, and is generated into a byte array, which is usually shown as base-32 or QR code on-screen to the user in the TOTP setup phase.
So long story short, there is nothing to worry about.
Thank you Patrick, can you tell me which method I need to use on the UserManager to get the secret as a byte to encode into base-32 for the setup phase? I was using UserManager.GetSecurityStampAsync but that must be where my implementation is wrong.
– Peter
Nov 28 '18 at 9:42
That would beGetSecurityStampAsyncorCreateSecurityTokenAsyncprobably.
– Patrick Hofman
Nov 28 '18 at 9:45
1
You're right, I was encoding the secret to a byte array using the incorrect encoding . I should use unicode. Thank you for the insight!
– Peter
Nov 28 '18 at 9:50
Yes, indeed. Good you found it.
– Patrick Hofman
Nov 28 '18 at 9:51
1
The sample projects are usually quite useful. See for example here: github.com/aspnet/Identity/blob/master/samples/…
– Patrick Hofman
Nov 28 '18 at 9:51
|
show 1 more comment
The TotpSecurityStampBasedTokenProvider uses UserManager.CreateSecurityTokenAsync to generate the secret code which is used to calculate the token.
The code relies on the user ID, and is generated into a byte array, which is usually shown as base-32 or QR code on-screen to the user in the TOTP setup phase.
So long story short, there is nothing to worry about.
Thank you Patrick, can you tell me which method I need to use on the UserManager to get the secret as a byte to encode into base-32 for the setup phase? I was using UserManager.GetSecurityStampAsync but that must be where my implementation is wrong.
– Peter
Nov 28 '18 at 9:42
That would beGetSecurityStampAsyncorCreateSecurityTokenAsyncprobably.
– Patrick Hofman
Nov 28 '18 at 9:45
1
You're right, I was encoding the secret to a byte array using the incorrect encoding . I should use unicode. Thank you for the insight!
– Peter
Nov 28 '18 at 9:50
Yes, indeed. Good you found it.
– Patrick Hofman
Nov 28 '18 at 9:51
1
The sample projects are usually quite useful. See for example here: github.com/aspnet/Identity/blob/master/samples/…
– Patrick Hofman
Nov 28 '18 at 9:51
|
show 1 more comment
The TotpSecurityStampBasedTokenProvider uses UserManager.CreateSecurityTokenAsync to generate the secret code which is used to calculate the token.
The code relies on the user ID, and is generated into a byte array, which is usually shown as base-32 or QR code on-screen to the user in the TOTP setup phase.
So long story short, there is nothing to worry about.
The TotpSecurityStampBasedTokenProvider uses UserManager.CreateSecurityTokenAsync to generate the secret code which is used to calculate the token.
The code relies on the user ID, and is generated into a byte array, which is usually shown as base-32 or QR code on-screen to the user in the TOTP setup phase.
So long story short, there is nothing to worry about.
answered Nov 28 '18 at 9:26
Patrick HofmanPatrick Hofman
128k18177235
128k18177235
Thank you Patrick, can you tell me which method I need to use on the UserManager to get the secret as a byte to encode into base-32 for the setup phase? I was using UserManager.GetSecurityStampAsync but that must be where my implementation is wrong.
– Peter
Nov 28 '18 at 9:42
That would beGetSecurityStampAsyncorCreateSecurityTokenAsyncprobably.
– Patrick Hofman
Nov 28 '18 at 9:45
1
You're right, I was encoding the secret to a byte array using the incorrect encoding . I should use unicode. Thank you for the insight!
– Peter
Nov 28 '18 at 9:50
Yes, indeed. Good you found it.
– Patrick Hofman
Nov 28 '18 at 9:51
1
The sample projects are usually quite useful. See for example here: github.com/aspnet/Identity/blob/master/samples/…
– Patrick Hofman
Nov 28 '18 at 9:51
|
show 1 more comment
Thank you Patrick, can you tell me which method I need to use on the UserManager to get the secret as a byte to encode into base-32 for the setup phase? I was using UserManager.GetSecurityStampAsync but that must be where my implementation is wrong.
– Peter
Nov 28 '18 at 9:42
That would beGetSecurityStampAsyncorCreateSecurityTokenAsyncprobably.
– Patrick Hofman
Nov 28 '18 at 9:45
1
You're right, I was encoding the secret to a byte array using the incorrect encoding . I should use unicode. Thank you for the insight!
– Peter
Nov 28 '18 at 9:50
Yes, indeed. Good you found it.
– Patrick Hofman
Nov 28 '18 at 9:51
1
The sample projects are usually quite useful. See for example here: github.com/aspnet/Identity/blob/master/samples/…
– Patrick Hofman
Nov 28 '18 at 9:51
Thank you Patrick, can you tell me which method I need to use on the UserManager to get the secret as a byte to encode into base-32 for the setup phase? I was using UserManager.GetSecurityStampAsync but that must be where my implementation is wrong.
– Peter
Nov 28 '18 at 9:42
Thank you Patrick, can you tell me which method I need to use on the UserManager to get the secret as a byte to encode into base-32 for the setup phase? I was using UserManager.GetSecurityStampAsync but that must be where my implementation is wrong.
– Peter
Nov 28 '18 at 9:42
That would be
GetSecurityStampAsync or CreateSecurityTokenAsync probably.– Patrick Hofman
Nov 28 '18 at 9:45
That would be
GetSecurityStampAsync or CreateSecurityTokenAsync probably.– Patrick Hofman
Nov 28 '18 at 9:45
1
1
You're right, I was encoding the secret to a byte array using the incorrect encoding . I should use unicode. Thank you for the insight!
– Peter
Nov 28 '18 at 9:50
You're right, I was encoding the secret to a byte array using the incorrect encoding . I should use unicode. Thank you for the insight!
– Peter
Nov 28 '18 at 9:50
Yes, indeed. Good you found it.
– Patrick Hofman
Nov 28 '18 at 9:51
Yes, indeed. Good you found it.
– Patrick Hofman
Nov 28 '18 at 9:51
1
1
The sample projects are usually quite useful. See for example here: github.com/aspnet/Identity/blob/master/samples/…
– Patrick Hofman
Nov 28 '18 at 9:51
The sample projects are usually quite useful. See for example here: github.com/aspnet/Identity/blob/master/samples/…
– Patrick Hofman
Nov 28 '18 at 9:51
|
show 1 more comment
The problem is that the TotpSecurityStampBasedTokenProvider provided by Microsoft.AspNet.Identity.Core implements a hardcoded timestep of 3 minutes. Google Authenticator uses a default value of 30 seconds, which can NOT be modified according to the documentation provided.
This causes different codes to be generated by both TOTP computations resulting in an always false authentication.
I have added a ticket to the github repository of aspnet.identity about this.
So for now nothing left for me to do than create my own totpProvider
add a comment |
The problem is that the TotpSecurityStampBasedTokenProvider provided by Microsoft.AspNet.Identity.Core implements a hardcoded timestep of 3 minutes. Google Authenticator uses a default value of 30 seconds, which can NOT be modified according to the documentation provided.
This causes different codes to be generated by both TOTP computations resulting in an always false authentication.
I have added a ticket to the github repository of aspnet.identity about this.
So for now nothing left for me to do than create my own totpProvider
add a comment |
The problem is that the TotpSecurityStampBasedTokenProvider provided by Microsoft.AspNet.Identity.Core implements a hardcoded timestep of 3 minutes. Google Authenticator uses a default value of 30 seconds, which can NOT be modified according to the documentation provided.
This causes different codes to be generated by both TOTP computations resulting in an always false authentication.
I have added a ticket to the github repository of aspnet.identity about this.
So for now nothing left for me to do than create my own totpProvider
The problem is that the TotpSecurityStampBasedTokenProvider provided by Microsoft.AspNet.Identity.Core implements a hardcoded timestep of 3 minutes. Google Authenticator uses a default value of 30 seconds, which can NOT be modified according to the documentation provided.
This causes different codes to be generated by both TOTP computations resulting in an always false authentication.
I have added a ticket to the github repository of aspnet.identity about this.
So for now nothing left for me to do than create my own totpProvider
answered Nov 28 '18 at 15:45
PeterPeter
9,1781461103
9,1781461103
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53515739%2fusing-totpsecuritystampbasedtokenprovider-for-totp-with-google-authenticator%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown