1

チュートリアルhttps://developers.google.com/+/web/signin/から簡単なGoogleサインインボタンを設定しましたが、どうすれば次のことができるか疑問に思っていました:

  1. @domain.com などを除いて、電子メール フィールドのすべてのドメインを制限します。したがって、johndoe@gmail.com は機能しませんが、johndoe@twitter.com は受け入れられます。理にかなっていますか?

  2. ユーザーが既に Google アカウントにログインしている場合、ユーザーに再度サインインを「強制」することはできますか?

ここに私のJavascript / jQueryコードがあります:

<script type="text/javascript">

      (function() {
       var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
       po.src = 'https://apis.google.com/js/client:plusone.js';
       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
     })();


  function signinCallback(authResult) {
  if (authResult['access_token']) {
    // Successfully authorized
    // Hide the sign-in button now that the user is authorized, for example:
    document.getElementById('signinButton').setAttribute('style', 'display: none');

    $('.inline-field-title').hide();


  } else if (authResult['error']) {
    // There was an error.
    // Possible error codes:
    //   "access_denied" - User denied access to your app
    //   "immediate_failed" - Could not automatically log in the user
    // console.log('There was an error: ' + authResult['error']);
  }
}


  function disconnectUser(access_token) {
  var revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token=' +
      access_token;

  // Perform an asynchronous GET request.
  $.ajax({
    type: 'GET',
    url: revokeUrl,
    async: false,
    contentType: "application/json",
    dataType: 'jsonp',
    success: function(nullResponse) {
      // Do something now that user is disconnected
      // The response is always undefined.
    },
    error: function(e) {
      // Handle the error
      // console.log(e);
      // You could point users to manually disconnect if unsuccessful
      // https://plus.google.com/apps
    }
  });

}
// Could trigger the disconnect on a button click

$('#revokeButton').click(disconnectUser);


</script>
4

1 に答える 1