Google API: convert auth_code to access_token | Python












0















I'm trying to convert an auth_code provided from client to a token on my backend. (front and back are two different serves).




scope='https://www.googleapis.com/auth/calendar'
code='code=4/nQCEBlo_YbWfOw1NXCWJ3UCyRzPT*****NJbda0eaXdmv032qX2PZhV4Cd2YzO3sPQ36*************'
# Exchange auth code for access token, refresh token, and ID token
c = client.credentials_from_code('***ClientID*****-*****************.apps.googleusercontent.com'
,'SECRET*********',scope,code)
print (c.id_token)




another try was:



    CLIENT_SECRET_FILE = 'client_secret.json'
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/calendar'],
'code=4/nQCEBlo_YbWfOw1NXC****************4Cd2Y*********mGgA')


I received this error:



    raise FlowExchangeError(error_msg)
oauth2client.client.FlowExchangeError: invalid_grantMalformed auth code.


any idea?
Thanks!










share|improve this question























  • It's Saying the request that you are making to the Google Auth Server is wrongly formed. Can you show the Sample implementation what you are doing?

    – Sharvin Shah
    Nov 22 '18 at 17:48











  • I’m trying to send the auth code to google servers for token convertion I’m not sure about the implementation or the syntax do you have example? Thanks

    – שגיא שלום
    Nov 22 '18 at 18:39













  • They have already shown the implementation in their guides. Are you following that? developers.google.com/identity/protocols/OAuth2WebServer

    – Sharvin Shah
    Nov 23 '18 at 5:06













  • This is not my case. the client open browser using server 1 receiving the auth_code, then calling server 2 which receives this code and need to covert it to a token. Then server2 will perform some actions using that token. I don't understand exactly how to use the conversion function - that is my issue here.

    – שגיא שלום
    Nov 23 '18 at 14:17


















0















I'm trying to convert an auth_code provided from client to a token on my backend. (front and back are two different serves).




scope='https://www.googleapis.com/auth/calendar'
code='code=4/nQCEBlo_YbWfOw1NXCWJ3UCyRzPT*****NJbda0eaXdmv032qX2PZhV4Cd2YzO3sPQ36*************'
# Exchange auth code for access token, refresh token, and ID token
c = client.credentials_from_code('***ClientID*****-*****************.apps.googleusercontent.com'
,'SECRET*********',scope,code)
print (c.id_token)




another try was:



    CLIENT_SECRET_FILE = 'client_secret.json'
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/calendar'],
'code=4/nQCEBlo_YbWfOw1NXC****************4Cd2Y*********mGgA')


I received this error:



    raise FlowExchangeError(error_msg)
oauth2client.client.FlowExchangeError: invalid_grantMalformed auth code.


any idea?
Thanks!










share|improve this question























  • It's Saying the request that you are making to the Google Auth Server is wrongly formed. Can you show the Sample implementation what you are doing?

    – Sharvin Shah
    Nov 22 '18 at 17:48











  • I’m trying to send the auth code to google servers for token convertion I’m not sure about the implementation or the syntax do you have example? Thanks

    – שגיא שלום
    Nov 22 '18 at 18:39













  • They have already shown the implementation in their guides. Are you following that? developers.google.com/identity/protocols/OAuth2WebServer

    – Sharvin Shah
    Nov 23 '18 at 5:06













  • This is not my case. the client open browser using server 1 receiving the auth_code, then calling server 2 which receives this code and need to covert it to a token. Then server2 will perform some actions using that token. I don't understand exactly how to use the conversion function - that is my issue here.

    – שגיא שלום
    Nov 23 '18 at 14:17
















0












0








0


1






I'm trying to convert an auth_code provided from client to a token on my backend. (front and back are two different serves).




scope='https://www.googleapis.com/auth/calendar'
code='code=4/nQCEBlo_YbWfOw1NXCWJ3UCyRzPT*****NJbda0eaXdmv032qX2PZhV4Cd2YzO3sPQ36*************'
# Exchange auth code for access token, refresh token, and ID token
c = client.credentials_from_code('***ClientID*****-*****************.apps.googleusercontent.com'
,'SECRET*********',scope,code)
print (c.id_token)




another try was:



    CLIENT_SECRET_FILE = 'client_secret.json'
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/calendar'],
'code=4/nQCEBlo_YbWfOw1NXC****************4Cd2Y*********mGgA')


I received this error:



    raise FlowExchangeError(error_msg)
oauth2client.client.FlowExchangeError: invalid_grantMalformed auth code.


any idea?
Thanks!










share|improve this question














I'm trying to convert an auth_code provided from client to a token on my backend. (front and back are two different serves).




scope='https://www.googleapis.com/auth/calendar'
code='code=4/nQCEBlo_YbWfOw1NXCWJ3UCyRzPT*****NJbda0eaXdmv032qX2PZhV4Cd2YzO3sPQ36*************'
# Exchange auth code for access token, refresh token, and ID token
c = client.credentials_from_code('***ClientID*****-*****************.apps.googleusercontent.com'
,'SECRET*********',scope,code)
print (c.id_token)




another try was:



    CLIENT_SECRET_FILE = 'client_secret.json'
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/calendar'],
'code=4/nQCEBlo_YbWfOw1NXC****************4Cd2Y*********mGgA')


I received this error:



    raise FlowExchangeError(error_msg)
oauth2client.client.FlowExchangeError: invalid_grantMalformed auth code.


any idea?
Thanks!







python oauth token






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 17:40









שגיא שלוםשגיא שלום

65




65













  • It's Saying the request that you are making to the Google Auth Server is wrongly formed. Can you show the Sample implementation what you are doing?

    – Sharvin Shah
    Nov 22 '18 at 17:48











  • I’m trying to send the auth code to google servers for token convertion I’m not sure about the implementation or the syntax do you have example? Thanks

    – שגיא שלום
    Nov 22 '18 at 18:39













  • They have already shown the implementation in their guides. Are you following that? developers.google.com/identity/protocols/OAuth2WebServer

    – Sharvin Shah
    Nov 23 '18 at 5:06













  • This is not my case. the client open browser using server 1 receiving the auth_code, then calling server 2 which receives this code and need to covert it to a token. Then server2 will perform some actions using that token. I don't understand exactly how to use the conversion function - that is my issue here.

    – שגיא שלום
    Nov 23 '18 at 14:17





















  • It's Saying the request that you are making to the Google Auth Server is wrongly formed. Can you show the Sample implementation what you are doing?

    – Sharvin Shah
    Nov 22 '18 at 17:48











  • I’m trying to send the auth code to google servers for token convertion I’m not sure about the implementation or the syntax do you have example? Thanks

    – שגיא שלום
    Nov 22 '18 at 18:39













  • They have already shown the implementation in their guides. Are you following that? developers.google.com/identity/protocols/OAuth2WebServer

    – Sharvin Shah
    Nov 23 '18 at 5:06













  • This is not my case. the client open browser using server 1 receiving the auth_code, then calling server 2 which receives this code and need to covert it to a token. Then server2 will perform some actions using that token. I don't understand exactly how to use the conversion function - that is my issue here.

    – שגיא שלום
    Nov 23 '18 at 14:17



















It's Saying the request that you are making to the Google Auth Server is wrongly formed. Can you show the Sample implementation what you are doing?

– Sharvin Shah
Nov 22 '18 at 17:48





It's Saying the request that you are making to the Google Auth Server is wrongly formed. Can you show the Sample implementation what you are doing?

– Sharvin Shah
Nov 22 '18 at 17:48













I’m trying to send the auth code to google servers for token convertion I’m not sure about the implementation or the syntax do you have example? Thanks

– שגיא שלום
Nov 22 '18 at 18:39







I’m trying to send the auth code to google servers for token convertion I’m not sure about the implementation or the syntax do you have example? Thanks

– שגיא שלום
Nov 22 '18 at 18:39















They have already shown the implementation in their guides. Are you following that? developers.google.com/identity/protocols/OAuth2WebServer

– Sharvin Shah
Nov 23 '18 at 5:06







They have already shown the implementation in their guides. Are you following that? developers.google.com/identity/protocols/OAuth2WebServer

– Sharvin Shah
Nov 23 '18 at 5:06















This is not my case. the client open browser using server 1 receiving the auth_code, then calling server 2 which receives this code and need to covert it to a token. Then server2 will perform some actions using that token. I don't understand exactly how to use the conversion function - that is my issue here.

– שגיא שלום
Nov 23 '18 at 14:17







This is not my case. the client open browser using server 1 receiving the auth_code, then calling server 2 which receives this code and need to covert it to a token. Then server2 will perform some actions using that token. I don't understand exactly how to use the conversion function - that is my issue here.

– שגיא שלום
Nov 23 '18 at 14:17














0






active

oldest

votes











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436000%2fgoogle-api-convert-auth-code-to-access-token-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436000%2fgoogle-api-convert-auth-code-to-access-token-python%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy