How to return `QR` Code Image from Laravel API to Angular 6 through JSON response?
up vote
0
down vote
favorite
I am creating a Google 2FA in my project.
I have this QR code generator from bacon qr code in my Laravel app (backend).
I want this to be returned as a JSON response to my Angular app (frontend) through API.
I have this code in my Laravel Controller
public function google2faAuth($id){
// Get User
$user = User::find($id);
// Initialise the 2FA class
$google2fa = app('pragmarx.google2fa');
// Save 2FA data to user2faAuth table
$twoFaAuth = new User2faAuth();
$twoFaAuth->userId = $user->id;
$twoFaAuth->secretCode = $google2fa->generateSecretKey();
$twoFaAuth->save();
// Create QR image
$QRImage = $google2fa->getQRCodeInline(
config('app.name'),
$user->email,
$twoFaAuth->secretCode
);
return response()->json($QRImage);
}
But what I received in my Angular app is something like this.
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAIAAAAiOjnJAAAFAElEQVR4nO3dwW7YNhRFwcbo/3+y0U0QaKOGMnlEyZ5ZGjGlpBfsA0k9/vr8/PwHVvvY/QJ8T4JFQrBICBYJwSIhWCQEi4RgkRAsEoJFQrBICBYJwSIhWCQEi4RgkRAsEoJFQrBICBYJwSIhWCQEi4RgkRAsEv+uHe7jY31Sz77VPj5r5nvus3ceGfPq33dmzOPv3vnv/DVmLBKCRUKwSCyusY6KumektrhaM62q4a7+fVfVScW/8zwzFgnBIiFYJMIa62jk/+VX65jjmFfrqrP6aeTnZ1bVdiNjzvz5e3o4mrFICBYJwSJxU421yqp9tKt1xkitNmNmv/KZzFgkBIuEYJF4WY01sy41M/7VZ428w3vrpxFmLBKCRUKwSNxUY62qJ2bOSK3a7xsZc6Teuvo+xZmwjhmLhGCRECwSYY3Vnaf+2jtcXXMa+fnRzH5lcQ5srye+E9+AYJEQLBK/nrPyUbh6fusJ/Rq+x38RMxYJwSIhWCQe1B9rVf+nVetMM/XZ1d4TxRrbzJrcPDMWCcEiIVgkFq9j1efBi/pg5lvFVbVLUVNefZYepLyAYJEQLBLhXmFdc9T9Guo+EUUP0uesaZmxSAgWCcEiseE81qrz4CP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BIuEYJEQLBKCReI/leHQVUfEkcoAAAAASUVORK5CYII="
How can I return this properly so that I can render this QR code image in my front end?
angular laravel httprequest response qr-code
add a comment |
up vote
0
down vote
favorite
I am creating a Google 2FA in my project.
I have this QR code generator from bacon qr code in my Laravel app (backend).
I want this to be returned as a JSON response to my Angular app (frontend) through API.
I have this code in my Laravel Controller
public function google2faAuth($id){
// Get User
$user = User::find($id);
// Initialise the 2FA class
$google2fa = app('pragmarx.google2fa');
// Save 2FA data to user2faAuth table
$twoFaAuth = new User2faAuth();
$twoFaAuth->userId = $user->id;
$twoFaAuth->secretCode = $google2fa->generateSecretKey();
$twoFaAuth->save();
// Create QR image
$QRImage = $google2fa->getQRCodeInline(
config('app.name'),
$user->email,
$twoFaAuth->secretCode
);
return response()->json($QRImage);
}
But what I received in my Angular app is something like this.
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAIAAAAiOjnJAAAFAElEQVR4nO3dwW7YNhRFwcbo/3+y0U0QaKOGMnlEyZ5ZGjGlpBfsA0k9/vr8/PwHVvvY/QJ8T4JFQrBICBYJwSIhWCQEi4RgkRAsEoJFQrBICBYJwSIhWCQEi4RgkRAsEoJFQrBICBYJwSIhWCQEi4RgkRAsEv+uHe7jY31Sz77VPj5r5nvus3ceGfPq33dmzOPv3vnv/DVmLBKCRUKwSCyusY6KumektrhaM62q4a7+fVfVScW/8zwzFgnBIiFYJMIa62jk/+VX65jjmFfrqrP6aeTnZ1bVdiNjzvz5e3o4mrFICBYJwSJxU421yqp9tKt1xkitNmNmv/KZzFgkBIuEYJF4WY01sy41M/7VZ428w3vrpxFmLBKCRUKwSNxUY62qJ2bOSK3a7xsZc6Teuvo+xZmwjhmLhGCRECwSYY3Vnaf+2jtcXXMa+fnRzH5lcQ5srye+E9+AYJEQLBK/nrPyUbh6fusJ/Rq+x38RMxYJwSIhWCQe1B9rVf+nVetMM/XZ1d4TxRrbzJrcPDMWCcEiIVgkFq9j1efBi/pg5lvFVbVLUVNefZ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EYJEQLBKCRUKwSAgWCcEiIVgkBIuEYJEQLBKCRUKwSAgWCcEiIVgkBIuEYJEQLBKCReI/leHQVUfEkcoAAAAASUVORK5CYII="
How can I return this properly so that I can render this QR code image in my front end?
angular laravel httprequest response qr-code
1
stackoverflow.com/questions/38812993/base64-to-image-angular-2/…, similar to what you're looking for. Use the base64 string that you receive in angular to create the image.
– v1shva
Nov 15 at 9:22
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am creating a Google 2FA in my project.
I have this QR code generator from bacon qr code in my Laravel app (backend).
I want this to be returned as a JSON response to my Angular app (frontend) through API.
I have this code in my Laravel Controller
public function google2faAuth($id){
// Get User
$user = User::find($id);
// Initialise the 2FA class
$google2fa = app('pragmarx.google2fa');
// Save 2FA data to user2faAuth table
$twoFaAuth = new User2faAuth();
$twoFaAuth->userId = $user->id;
$twoFaAuth->secretCode = $google2fa->generateSecretKey();
$twoFaAuth->save();
// Create QR image
$QRImage = $google2fa->getQRCodeInline(
config('app.name'),
$user->email,
$twoFaAuth->secretCode
);
return response()->json($QRImage);
}
But what I received in my Angular app is something like this.
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAIAAAAiOjnJAAAFAElEQVR4nO3dwW7YNhRFwcbo/3+y0U0QaKOGMnlEyZ5ZGjGlpBfsA0k9/vr8/PwHVvvY/QJ8T4JFQrBICBYJwSIhWCQEi4RgkRAsEoJFQrBICBYJwSIhWCQEi4RgkRAsEoJFQrBICBYJwSIhWCQEi4RgkRAsEv+uHe7jY31Sz77VPj5r5nvus3ceGfPq33dmzOPv3vnv/DVmLBKCRUKwSCyusY6KumektrhaM62q4a7+fVfVScW/8zwzFgnBIiFYJMIa62jk/+VX65jjmFfrqrP6aeTnZ1bVdiNjzvz5e3o4mrFICBYJwSJxU421yqp9tKt1xkitNmNmv/KZzFgkBIuEYJF4WY01sy41M/7VZ428w3vrpxFmLBKCRUKwSNxUY62qJ2bOSK3a7xsZc6Teuvo+xZmwjhmL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v5YfBOCRUKwSLy4xiruez4b/+oaW12rrTpb1q2NmbFICBYJwSKxuT/WrufuupNn5H1W3Us98z7zzFgkBIuEYJEIa6z6/NCq9aFVZ8VWrZONnMcq+qbaK+QFBIuEYJF4WX8s3sKMRUKwSAgWCcEiIVgkBIuEYJEQLBKCRUKwSAgWCcEiIVgkBIuEYJEQLBKCRUKwSAgWCcEiIVgkBIuEYJEQLBKCReI/leHQVUfEkcoAAAAASUVORK5CYII="
How can I return this properly so that I can render this QR code image in my front end?
angular laravel httprequest response qr-code
I am creating a Google 2FA in my project.
I have this QR code generator from bacon qr code in my Laravel app (backend).
I want this to be returned as a JSON response to my Angular app (frontend) through API.
I have this code in my Laravel Controller
public function google2faAuth($id){
// Get User
$user = User::find($id);
// Initialise the 2FA class
$google2fa = app('pragmarx.google2fa');
// Save 2FA data to user2faAuth table
$twoFaAuth = new User2faAuth();
$twoFaAuth->userId = $user->id;
$twoFaAuth->secretCode = $google2fa->generateSecretKey();
$twoFaAuth->save();
// Create QR image
$QRImage = $google2fa->getQRCodeInline(
config('app.name'),
$user->email,
$twoFaAuth->secretCode
);
return response()->json($QRImage);
}
But what I received in my Angular app is something like this.
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAIAAAAiOjnJAAAFAElEQVR4nO3dwW7YNhRFwcbo/3+y0U0QaKOGMnlEyZ5ZGjGlpBfsA0k9/vr8/PwHVvvY/QJ8T4JFQrBICBYJwSIhWCQEi4RgkRAsEoJFQrBICBYJwSIhWCQEi4RgkRAsEoJFQrBICBYJwSIhWCQEi4RgkRAsEv+uHe7jY31Sz77VPj5r5nvus3ceGfPq33dmzOPv3vnv/DVmLBKCRUKwSCyusY6KumektrhaM62q4a7+fVfVScW/8zwzFgnBIiFYJMIa62jk/+VX65jjmFfrqrP6aeTnZ1bVdiNjzvz5e3o4mrFICBYJwSJxU421yqp9tKt1xkitNmNmv/KZzFgkBIuEYJF4WY01sy41M/7VZ428w3vrpxFmLBKCRUKwSNx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Jne9K68iGCRECwSD7pLp3DnHTgjzx15h6K3lv5YfBOCRUKwSLy4xiruez4b/+oaW12rrTpb1q2NmbFICBYJwSKxuT/WrufuupNn5H1W3Us98z7zzFgkBIuEYJEIa6z6/NCq9aFVZ8VWrZONnMcq+qbaK+QFBIuEYJF4WX8s3sKMRUKwSAgWCcEiIVgkBIuEYJEQLBKCRUKwSAgWCcEiIVgkBIuEYJEQLBKCRUKwSAgWCcEiIVgkBIuEYJEQLBKCReI/leHQVUfEkcoAAAAASUVORK5CYII="
How can I return this properly so that I can render this QR code image in my front end?
angular laravel httprequest response qr-code
angular laravel httprequest response qr-code
asked Nov 15 at 9:05
Jay Marz
54231833
54231833
1
stackoverflow.com/questions/38812993/base64-to-image-angular-2/…, similar to what you're looking for. Use the base64 string that you receive in angular to create the image.
– v1shva
Nov 15 at 9:22
add a comment |
1
stackoverflow.com/questions/38812993/base64-to-image-angular-2/…, similar to what you're looking for. Use the base64 string that you receive in angular to create the image.
– v1shva
Nov 15 at 9:22
1
1
stackoverflow.com/questions/38812993/base64-to-image-angular-2/…, similar to what you're looking for. Use the base64 string that you receive in angular to create the image.
– v1shva
Nov 15 at 9:22
stackoverflow.com/questions/38812993/base64-to-image-angular-2/…, similar to what you're looking for. Use the base64 string that you receive in angular to create the image.
– v1shva
Nov 15 at 9:22
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
This is base 64 content of the scanned QR image. Try looking for base 64 to image conversion, and then display the data in your front end using the img tag.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
This is base 64 content of the scanned QR image. Try looking for base 64 to image conversion, and then display the data in your front end using the img tag.
add a comment |
up vote
1
down vote
accepted
This is base 64 content of the scanned QR image. Try looking for base 64 to image conversion, and then display the data in your front end using the img tag.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
This is base 64 content of the scanned QR image. Try looking for base 64 to image conversion, and then display the data in your front end using the img tag.
This is base 64 content of the scanned QR image. Try looking for base 64 to image conversion, and then display the data in your front end using the img tag.
answered Nov 15 at 9:16
Nikhil Sridhar
454
454
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53315788%2fhow-to-return-qr-code-image-from-laravel-api-to-angular-6-through-json-respons%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
1
stackoverflow.com/questions/38812993/base64-to-image-angular-2/…, similar to what you're looking for. Use the base64 string that you receive in angular to create the image.
– v1shva
Nov 15 at 9:22