Redirect URI not redirecting correctly

你。 提交于 2019-12-25 05:34:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!