Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Windows Azure > Windows Azure (Mobile Services) and HTML/JavaScript (jQuery) > ตอนที่ 5 : การทำ Authentication in Azure Mobile Services ด้วย HTML และ JavaScript



Clound SSD Virtual Server

ตอนที่ 5 : การทำ Authentication in Azure Mobile Services ด้วย HTML และ JavaScript

ตอนที่ 5 : การทำ Authentication in Azure Mobile Services ด้วย HTML และ JavaScript ความสามารถของ HTML และ JavaScript จะมี API ที่ช่วยตรวจสอบและติดต่อกับ Social Network พวก Twitter , Facebook หรือ Google Account ได้ เช่นการโพสข้อความ หรือการแสดงข้อมูลต่าง ๆ จาก Social Network ที่เรา Login ในเครื่องนั้น ได้ และบน Mobile Services ของ Windows Azure ก็สามารถที่จะทำการเชื่อมต่อไปยัง Social Network เหล่านั้นได้เช่นเดียวกัน โดยในปัจจุบันของรับ 4 ตัวด้วยกันคือ

  • Microsoft Account
  • Facebook login
  • Twitter login
  • Google login


ในการเขียน Mobile Services เพื่อทำการ Authentication Account จาก Social และ Provider เหล่านี้ เราจะต้องทำการ Register เพื่อขอพวก ID จาก Provider นั้น ๆ ก่อน

 Authentication in Azure Mobile Services

ตอนนี้เรามี Mobile Services ทีได้สร้างไว้ก่อนหน้านี้แล้ว 1 รายการ

 Authentication in Azure Mobile Services

หน้าจอ Dashboard ของ Mobile Services จะมี URL ของ Mobile Services อยู่ ซึ่งเราจะต้องเอา URL นี้ไปทำการ Register กับ Social ของค่ายนั้น ๆ ก่อน

 Authentication in Azure Mobile Services

หน้าจอสำหรับการกำหนด ID ของ Social แต่ล่ะค่าย

ลงทะบียนของแต่ล่ะค่ายได้ตาม Link นี้









Example ในตัวอย่างนี้เราจะกำหนดว่าจะต้อง Login ผ่าน Social Provider ของ Google ก่อนถึงจะสามารถดูข้อมูลได้

 Authentication in Azure Mobile Services

ให้ไปที่ DATA เลือก Table ที่ต้องการ

 Authentication in Azure Mobile Services

ในส่วนของ PERMISSIONS ให้เลือกเป็นแบบ Only Authenticateds Users

จากนั้นในส่วนของ Code สามารถที่จะเขียนดักการ Authentication ด้วยคำสั่งง่าย ๆ นี้

				function refreshAuthDisplay() {
						var isLoggedIn = client.currentUser !== null;
						$("#logged-in").toggle(isLoggedIn);
						$("#logged-out").toggle(!isLoggedIn);

						if (isLoggedIn) {
							$("#login-name").text(client.currentUser.userId);
							refreshMyMember();
						}
				}


Code ทั้งหมด

<!DOCTYPE html>
<html>
    <head>
        <meta charset='utf-8' />
        <title>ThaiCreate.Com</title>
        <link rel='stylesheet' href='styles.css' />
        <meta name='viewport' content='width=device-width' />
        <!--[if lt IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js"></script><![endif]-->
        <script src='https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js'></script>
        <script src='https://thaicreate.azure-mobile.net/client/MobileServices.Web-1.0.0.min.js'></script>
    </head>
    <body>

	<script type="text/javascript">
		$(document).ready(function(){

				var client = new WindowsAzure.MobileServiceClient('https://thaicreate.azure-mobile.net/', 'uJPAhkAkcTBuTyCNxaOSnDKFzkoYqB49'),

				myMemberTable = client.getTable('MyMember');

				function refreshMyMember() {
					var query = myMemberTable.orderBy("id")

					query.read().then(function(mymemberItems) {
						var listItems = $.map(mymemberItems, function(item) {
							return $('<li>')
								.attr('data-todoitem-id', item.id)
								.append($('<div>name : '+item.name+'&nbsp;&nbsp;&nbsp; email : '+item.email+' &nbsp; status : '+item.status+'</div>')
								);
						});

						$('#todo-items').empty().append(listItems).toggle(listItems.length > 0);
						$('#summary').html('<strong>' + mymemberItems.length + '</strong> item(s)');
					}, handleError);
				}

				function handleError(error) {
					var text = error + (error.request ? ' - ' + error.request.status : '');
					$('#errorlog').append($('<li>').text(text));
				}

				function refreshAuthDisplay() {
						var isLoggedIn = client.currentUser !== null;
						$("#logged-in").toggle(isLoggedIn);
						$("#logged-out").toggle(!isLoggedIn);

						if (isLoggedIn) {
							$("#login-name").text(client.currentUser.userId);
							refreshMyMember();
						}
				}

				function logIn() {
						client.login("google").then(refreshAuthDisplay, function(error){
							alert(error);
						});
				}

				function logOut() {
					client.logout();
					refreshAuthDisplay();
					$('#summary').html('<strong>You must login to access data.</strong>');
				}

				 refreshAuthDisplay();
					$('#summary').html('<strong>You must login to access data.</strong>');          
					$("#logged-out button").click(logIn);
					$("#logged-in button").click(logOut);

		});
	</script>

        <div id='wrapper'>
            <article>
                <header>
                    <h2>Windows Azure</h2>
                    <h1>Mobile Services</h1>
                </header>

                <ul id='todo-items'></ul>
                <p id='summary'>Loading...</p>

				<div id="logged-in">
					&nbsp;You are logged in as <span id="login-name"></span>.
					<button id="log-out">Log out</button>
				</div>
				<div id="logged-out">
					&nbsp;You are not logged in.
					<button>Log in</button>
				</div>
				<br>
            </article>

            <footer>
                <a href='http://www.windowsazure.com/en-us/develop/mobile/'>
                    Learn more about Windows Azure Mobile Services
                </a>
                <ul id='errorlog'></ul>
            </footer>
        </div>

    </body>
</html>


Screenshot

 Authentication in Azure Mobile Services

กรณีที่ไม่ได้ Login ผ่าน Social และ Provider เหล่า

 Authentication in Azure Mobile Services

กรณีที่ Login ผ่านก็จะมีสิทธิ์เห็นข้อมูล








บทความถัดไปที่แนะนำให้อ่าน


บทความที่เกี่ยวข้อง


   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2013-08-26 06:10:50 / 2017-03-24 12:03:07
  Download : Download  ตอนที่ 5 : การทำ Authentication in Azure Mobile Services ด้วย HTML และ JavaScript
 Sponsored Links / Related

 
ตอนที่ 1 : การสร้าง Azure Mobile Services ทำงานร่วมกับ HTML และ JavaScript
Rating :

 
ตอนที่ 2 : สร้าง Table และ Insert ข้อมูล Azure Mobile Services ด้วย HTML และ JavaScript
Rating :

 
ตอนที่ 3 : อ่าน Data จาก Table ของ Azure Mobile Services และแสดงผลบน HTML และ JavaScript
Rating :

 
ตอนที่ 4 : อ่านข้อมูล Azure Mobile Services แบบมีเงื่อนไข Where และแสดงผล HTML และ JavaScript
Rating :

 
ตอนที่ 6 : การทำ Validate และ Modify data in Mobile Services บน HTML และ JavaScript
Rating :

 
ตอนที่ 7 : การทำ Refine Mobile Services queries with paging บน HTML และ JavaScript
Rating :

 
ตอนที่ 8 : การเขียน Scripts to authorize users in Mobile Services บน HTML และ JavaScript
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่