|
18 | 18 | <ul>
|
19 | 19 | <li><a href="#introduction">Introduction</a></li>
|
20 | 20 | <li><a href="#getting-started">Getting Started</a></li>
|
| 21 | + <li><a href="#html5">HTML5 mode</a></li> |
21 | 22 | <li><a href="#howto">How To</a></li>
|
22 | 23 | <li><a href="#configurations">Configurations</a></li>
|
23 | 24 | <li><a href="#customizations">Customizations</a></li>
|
@@ -82,16 +83,56 @@ <h2>Basic Example</h2>
|
82 | 83 | To fully understand how it works read the <a href="#howto">next section</a>.
|
83 | 84 | </p>
|
84 | 85 |
|
| 86 | + |
85 | 87 | <h2>What does it do?</h2>
|
86 | 88 |
|
87 | 89 | <p>
|
88 | 90 | It renders a Login link that lets you authorize a third party app through OAuth 2.0.
|
89 | 91 | 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>.
|
90 | 92 | </p>
|
91 | 93 |
|
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. |
95 | 136 | </p>
|
96 | 137 |
|
97 | 138 | </div>
|
@@ -211,6 +252,17 @@ <h2>AngularJS app definition</h2>
|
211 | 252 | <pre><code><xmp>// app/scripts/app.js
|
212 | 253 | angular.module('newProjectApp', ['oauth', ... ])</xmp></code></pre>
|
213 | 254 |
|
| 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 | + |
214 | 266 | <h2 id="server">OAuth 2.0 Server</h2>
|
215 | 267 |
|
216 | 268 | <p>
|
@@ -681,7 +733,7 @@ <h1 id="events">Events</h1>
|
681 | 733 | <td>
|
682 | 734 | Fired when the view is initializing and user has a non-expired auth token in the local session storage.
|
683 | 735 | </td>
|
684 |
| - </tr> |
| 736 | + </tr> |
685 | 737 | <tr>
|
686 | 738 | <td class="parameter">
|
687 | 739 | <span>oauth:logout</span>
|
@@ -755,7 +807,9 @@ <h1 id="logged">Logged in or logged out?</h1>
|
755 | 807 | Inject the <code>AccessToken.get()</code> service to understand if the user is logged in or out.
|
756 | 808 | </p>
|
757 | 809 |
|
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> |
759 | 813 |
|
760 | 814 | <p>
|
761 | 815 | The <code>AccessToken.get()</code> method returns <code>null</code> when the user is logged
|
|
0 commit comments