问题
I've specified my Redirect URI in my account setup, but I'm not sure about where to specify it in my code.
I'm using the "sign in with google" button, and I'm able to sign in, but the redirect_uri that I'm always seeing when I use fiddler is the same URI that I'm posting to. I'd like to have a different one.
I'm sure this has to do with me not looking in the right place for instructions, as I'm new to OpenID connect. I thought setting the meta tag would do the trick if the URI matched the redirect_uri I'd listed in my registered redirect URIs.
Here's my HTML page:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="xxxxxxxxxxxxxx-yyyyyyyyyyyyyyyyyy.apps.googleusercontent.com">
<meta name="google-signin-redirect_uri" content="https://www.apple.com">
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log("Name: " + profile.getName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
};
</script>
</form>
</body>
</html>
回答1:
To make use of redirect_uri you have to declare it as g-signin2 data parameter and explicitly request accesstype = offline.
<div class="g-signin2"
data-onsuccess="onSignIn"
data-scope="https://www.googleapis.com/auth/plus.login"
data-accesstype="offline"
data-redirecturi="https://www.example.com/redirect_uri"></div>
This way access code will be sent to requested uri. Detailed docs for server side flow.
来源:https://stackoverflow.com/questions/30653847/redirect-uri-not-redirecting-correctly