Skip to content

Commit b304fe7

Browse files
Added documentation related to the HTML5 mode on or off
1 parent 01eb315 commit b304fe7

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

index.html

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ul>
1919
<li><a href="#introduction">Introduction</a></li>
2020
<li><a href="#getting-started">Getting Started</a></li>
21+
<li><a href="#html5">HTML5 mode</a></li>
2122
<li><a href="#howto">How To</a></li>
2223
<li><a href="#configurations">Configurations</a></li>
2324
<li><a href="#customizations">Customizations</a></li>
@@ -82,16 +83,56 @@ <h2>Basic Example</h2>
8283
To fully understand how it works read the <a href="#howto">next section</a>.
8384
</p>
8485

86+
8587
<h2>What does it do?</h2>
8688

8789
<p>
8890
It renders a Login link that lets you authorize a third party app through OAuth 2.0.
8991
When the flow is completed, the access token is saved in the <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage#sessionStorage" target="_blank">SessionStorage</a>.
9092
</p>
9193

92-
<p class="notice">
93-
The oauth directive only works in HTML5 mode (automatically activated). <br>
94-
We are working on fixing this <a href="https://github.com/andreareginato/oauth-ng/issues/13">bug</a>.
94+
</div>
95+
</section>
96+
97+
98+
<section>
99+
<div class="content">
100+
101+
<h1 id="html5">HTML5 mode</h1>
102+
103+
104+
<h2>HTML5 mode ON</h2>
105+
106+
<p>The oauth directive works just straight when the <a href="https://docs.angularjs.org/guide/$location#general-overview-of-the-api">HTML5 mode</a> is active.</p>
107+
108+
<pre><code><xmp><script>
109+
angular.module('app').config(function($locationProvider) {
110+
$locationProvider.html5Mode(true).hashPrefix('!');
111+
});</script></xmp></code></pre>
112+
113+
114+
<h2>HTML5 mode OFF</h2>
115+
116+
<p>When the HTML5 mode is off add the following snippet of code to your routing provider.</p>
117+
118+
<pre><code><xmp>angular.module('app').config(function ($routeProvider) {
119+
$routeProvider
120+
.when('/access_token=:accessToken', {
121+
template: '',
122+
controller: function ($location, AccessToken) {
123+
var hash = $location.path().substr(1);
124+
AccessToken.setTokenFromString(hash);
125+
$location.path('/');
126+
$location.replace();
127+
}
128+
})
129+
...</xmp></code></pre>
130+
131+
132+
<p>
133+
This code is needed because the fragment that the OAuth 2.0 server returns is recognized
134+
as the routing path <code>/access_token</code>. For this reason you need to add a routing
135+
rule catching the access token, parse it and then redirect to the desired view of your app.
95136
</p>
96137

97138
</div>
@@ -211,6 +252,17 @@ <h2>AngularJS app definition</h2>
211252
<pre><code><xmp>// app/scripts/app.js
212253
angular.module('newProjectApp', ['oauth', ... ])</xmp></code></pre>
213254

255+
<h2>Activate the HTML5 mode</h2>
256+
257+
<p>
258+
Activate the HTML5 mode to easily catch the access token.
259+
</p>
260+
261+
<pre><code><xmp>// app/scripts/app.js
262+
angular.module('newProjectApp').config(function($locationProvider) {
263+
$locationProvider.html5Mode(true).hashPrefix('!');
264+
});</xmp></code></pre>
265+
214266
<h2 id="server">OAuth 2.0 Server</h2>
215267

216268
<p>
@@ -681,7 +733,7 @@ <h1 id="events">Events</h1>
681733
<td>
682734
Fired when the view is initializing and user has a non-expired auth token in the local session storage.
683735
</td>
684-
</tr>
736+
</tr>
685737
<tr>
686738
<td class="parameter">
687739
<span>oauth:logout</span>
@@ -755,7 +807,9 @@ <h1 id="logged">Logged in or logged out?</h1>
755807
Inject the <code>AccessToken.get()</code> service to understand if the user is logged in or out.
756808
</p>
757809

758-
<pre><code><xmp>$scope.logged = !!AccessToken.get();</xmp></code></pre>
810+
<pre><code><xmp>$timeout(function() {
811+
$scope.logged = !!AccessToken.get();
812+
}, 0)</xmp></code></pre>
759813

760814
<p>
761815
The <code>AccessToken.get()</code> method returns <code>null</code> when the user is logged

0 commit comments

Comments
 (0)