You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-17Lines changed: 22 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,16 +68,24 @@ By default, this application uses a mock authorization server which responds to
68
68
69
69
To start the mock server, run the following in a second terminal window:
70
70
```bash
71
-
# Starts the mock Okta server at http://127.0.0.01:7777
71
+
# Starts the mock Okta server at http://127.0.0.1:7777
72
72
[samples-java-spring-mvc]$ npm run mock-okta
73
73
```
74
74
75
-
If you'd like to test this sample against your own Okta org, follow [these steps to setup an OpenID Connect app](docs/assets/oidc-app-setup.md). Then, replace the *oidc* settings in `samples.config.json` to point to your new app:
75
+
If you'd like to test this sample against your own Okta org, navigate to the Okta Developer Dashboard and follow these steps:
76
+
77
+
1. Create a new **Web** application by selecting **Create New Application** from the *Applications* page.
78
+
2. After accepting the default configuration, select **Create Application** to redirect back to the *General Settings* of your application.
79
+
3. Copy the **Client ID** and **Client Secret**, as it will be needed for the client configuration.
80
+
4. Finally, navigate to `https://{yourOktaDomain}.com/oauth2/default` to see if the [Default Authorization Server](https://developer.okta.com/docs/api/resources/oauth2.html#using-the-default-authorization-server) is setup. If not, [let us know](mailto:developers@okta.com).
81
+
82
+
Then, replace the *oidc* settings in `.samples.config.json` to point to your new app:
@@ -103,6 +111,7 @@ class LoginRedirectController {
103
111
$onInit() {
104
112
this.authClient=newOktaAuth({
105
113
url:this.config.oktaUrl,
114
+
issuer:this.config.issuer,
106
115
clientId:this.config.clientId,
107
116
redirectUri:this.config.redirectUri,
108
117
scopes: ['openid', 'email', 'profile'],
@@ -122,7 +131,6 @@ There are a number of different ways to construct the login redirect URL.
122
131
3. Use [AuthJS](http://developer.okta.com/code/javascript/okta_auth_sdk)
123
132
124
133
In this sample, we use AuthJS to create the URL and perform the redirect. An `OktaAuth` object is instantiated with the configuration in `.samples.config.json`. When the `login()` function is called from the view, it calls the [`/authorize`](http://developer.okta.com/docs/api/resources/oauth2.html#authentication-request) endpoint to start the [Authorization Code Flow](https://tools.ietf.org/html/rfc6749#section-1.3.1).
125
-
126
134
127
135
You can read more about the `OktaAuth` configuration options here: [OpenID Connect with Okta AuthJS SDK](http://developer.okta.com/code/javascript/okta_auth_sdk#social-authentication-and-openid-connect).
128
136
@@ -150,6 +158,7 @@ class LoginCustomController {
150
158
clientId:this.config.clientId,
151
159
redirectUri:this.config.redirectUri,
152
160
authParams: {
161
+
issuer:this.config.issuer,
153
162
responseType:'code',
154
163
scopes: ['openid', 'email', 'profile'],
155
164
},
@@ -241,7 +250,6 @@ public String callback(@RequestParam("state") String state,
241
250
### Code Exchange
242
251
Next, we exchange the returned authorization code for an `id_token` and/or `access_token`. You can choose the best [token authentication method](http://developer.okta.com/docs/api/resources/oauth2.html#token-request) for your application. In this sample, we use the default token authentication method `client_secret_basic`:
After receiving the `id_token`, we [validate](http://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation) the token and its claims to prove its integrity.
292
300
293
-
In this sample, we use a [JSON Object Signing and Encryption (JOSE)](https://bitbucket.org/b_c/jose4j/wiki/Home) library to decode and validate the token.
301
+
In this sample, we use the a [JSON Object Signing and Encryption (JOSE)](https://bitbucket.org/b_c/jose4j/wiki/Home) library to decode and validate the token.
294
302
295
303
There are a couple things we need to verify:
296
304
@@ -308,7 +316,6 @@ For example:
308
316
- If the `kid` has been cached, use it to validate the signature.
309
317
- If not, make a request to the `jwks_uri`. Cache the new `jwks`, and use the response to validate the signature.
The `iat` value indicates what time the token was "issued at". We verify that this claim is valid by checking that the token was not issued in the future, with some leeway for clock skew.
377
382
@@ -421,17 +426,18 @@ In Spring MVC, you can clear the the user session by:
421
426
// Application.java
422
427
423
428
public String logout(HttpServletRequest request) {
424
-
request.getSession().invalidate();
425
-
user = new User();
426
-
return"redirect:/";
427
-
}
429
+
request.getSession().invalidate();
430
+
user = new User();
431
+
return"redirect:/";
432
+
}
428
433
```
434
+
429
435
The Okta session is terminated in our client-side code.
430
436
431
437
## Conclusion
432
438
You have now successfully authenticated with Okta! Now what? With a user's `id_token`, you have basic claims into the user's identity. You can extend the set of claims by modifying the `response_type` and `scopes` to retrieve custom information about the user. This includes `locale`, `address`, `phone_number`, `groups`, and [more](http://developer.okta.com/docs/api/resources/oidc.html#scopes).
433
439
434
-
## Support
440
+
## Support
435
441
436
442
Have a question or see a bug? Email developers@okta.com. For feature requests, feel free to open an issue on this repo. If you find a security vulnerability, please follow our [Vulnerability Reporting Process](https://www.okta.com/vulnerability-reporting-policy/).
437
443
@@ -442,4 +448,3 @@ Copyright 2017 Okta, Inc. All rights reserved.
442
448
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
443
449
444
450
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
0 commit comments