-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathauth.html
223 lines (190 loc) · 7.28 KB
/
auth.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" data-app-id="YOUR_CLIENT_ID_HERE" src="https://assets.yammer.com/assets/platform_js_sdk.js"></script>
</head>
<body onload="login()">
<script>
yam.connect.embedFeed({
container: '#embedded-feed',
feedType: 'open-graph',
feedId: '',
config: {
use_sso: false,
header: true,
footer: true,
showOpenGraphPreview: false
},
objectProperties: {
url: '',
type: 'page'
}
});
yam.connect.actionButton({
container: "#embedded-follow",
action: "follow"
});
yam.connect.actionButton({
container: "#embedded-like",
action: "like"
});
yam.config({
debug: true
});
function logout() {
yam.getLoginStatus(
function (response) {
if (response.authResponse) {
yam.logout(function (response) {
toggleLoginStatus(false);
location.reload();
})
}
}
);
}
function toggleLoginStatus(loggedIn) {
if (loggedIn) {
$('.not-logged-in').hide();
$('.logged-in').show('slow');
} else {
$('.not-logged-in').show('slow');
$('.logged-in').hide();
}
}
function displayAuthResult(authResult) {
console.log("AuthResult", authResult); //print user information to the console
$('#yammer-login').innerHTML = 'Welcome to Yammer!';
toggleLoginStatus(true);
$('#authResult').html('Auth Result:<br/>');
for (var field in authResult) {
$('#authResult').append(' ' + field + ': ' +
authResult[field] + '<br/>');
}
$('#authOps').show('slow');
}
function getCurrentUser() {
yam.platform.request({
// yam.request({
url: "users/current.json", //this is one of many REST endpoints that are available
method: "GET",
data: {},
success: function (user) { //print message response information to the console
console.log("User request was successful.");
console.dir(user);
toggleLoginStatus(true);
$('#authResult').html('User Result:<br/>');
for (var field in user) {
$('#authResult').append(' ' + field + ': ' +
escape(user[field]) + '<br/>');
}
},
error: function (user) {
console.error("There was an error with the request.");
}
});
}
function getCurrentGroups() {
yam.platform.request({
url: "groups.json?mine=1",
method: "GET",
data: {},
success: function (group) {
$mygroup = "";
for ($i = 0; $i < group.length; $i++) {
$mygroup += '<img src="' + group[$i].mugshot_url + '">' + " " + group[$i].full_name + "," + "<br>";
}
$("#yammer-group-button").html($mygroup);
},
error: function (group) {
console.error("There was an error with the request.");
}
});
}
function login() {
console.log("Trigger setAuthToken");
yam.platform.setAuthToken({
token: localStorage.getItem(1)
},
function (response) {
if (response.authResponse) {
console.log("Logged in and got code");
displayAuthResult(response.access_token);
} else {
console.log("Not logged in.");
}
});
};
function logout() {
yam.getLoginStatus(
function (response) {
if (response.authResponse) {
yam.logout(function (response) {
console.log("User was logged out");
location.reload();
})
} else {
toggleLoginStatus(false);
}
}
);
}
$(document).ready(function () {
$('#disconnect').click(logout);
$('#yammer-user-button').click(getCurrentUser);
$('#yammer-group-button').click(getCurrentGroups);
});
</script>
<div id='page'>
<div>
<h2>JS SDK</h2>
<button id="yammer-user-button">Get Current User</button>
<button id="yammer-group-button">Get Current Groups</button>
</div>
<a name="setauthtoken" class="anchor" href="#setauthtoken"><span class="mini-icon mini-icon-link"></span></a>setAuthToken</h2>
<pre><code>yam.platform.setAuthToken(token, [callback])
</code></pre>
<p>Sets a specific auth token string which may have been stored locally or which has been retrieved through the <code>/api/v1/oauth/tokens.json</code> endpoint for example. This token will be used blindly for subsequent <code>yam.platform.request</code> calls.
<br>Alternatively if a callback is provided the token will be checked for validity against the API. If the token is not valid the user will be effectively left in a logged out state.</p>
<p>This method calls the endpoint <a href="https://api.yammer.com/api/v1/oauth2/token.json">https://api.yammer.com/api/v1/oauth2/token.json</a>
</p>
<div class="logged-in" style="display:none">
<p>User is now signed in to the app using Yammer</p>
<button id="disconnect" class="yj-btn yj-btn-alt">Log out from your Yammer account</button>
</div>
<div class="logged-in" style="display:none">
<h2>Authentication Logs</h2>
<pre id="authResult"></pre>
</div>
</div>
<div id="embedded-follow"></div>
<div id="embedded-like"></div>
<div id="embedded-feed" style="height:400px;width:500px;"></div>
<script>
yam.connect.embedFeed({
container: '#embedded-feed',
feedType: 'open-graph',
feedId: '',
config: {
use_sso: false,
header: true,
footer: true,
showOpenGraphPreview: false
},
objectProperties: {
url: '',
type: 'page'
}
});
yam.connect.actionButton({
container: "#embedded-follow",
action: "follow"
});
yam.connect.actionButton({
container: "#embedded-like",
action: "like"
});
</script>
</body>
</html>