|
| 1 | + |
| 2 | +# POC for an OAuth2-based Architecture running behind an API Gateway |
| 3 | + |
| 4 | +## Overview |
| 5 | +Here are all the individual services: |
| 6 | +- `service-registry-1` - the Eureka-based service registry |
| 7 | +- `api-gateway-zuul-1` - the Zuul-based API Gateway |
| 8 | +- `authorization-server-1` - the Authoization Server |
| 9 | +- `resource-server-mvc-1` - the Resource Server |
| 10 | + |
| 11 | +Note that these are all implemented using Spring Boot 1.x |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +## Ops |
| 16 | +When starting up the services, the sequence should be - `service-registry-1` first, everything else after. |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +## Run |
| 21 | +Once everything starts up, try to access the Resource Server, through the Gateway: |
| 22 | +`http://localhost:8765/resource-server-mvc-1` |
| 23 | + |
| 24 | +Or, if you're authenticating with an admin: |
| 25 | +`http://localhost:8765/resource-server-mvc-1/secret` |
| 26 | + |
| 27 | +You'll be redirected to the Authorization Server to authenticate. |
| 28 | +Use the following credentials: `user`/`password` or `admin`/`admin`. |
| 29 | +And approve the authorization for the `fooScope` OAuth scope. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +## High-Level Flow |
| 34 | + |
| 35 | +Here's what the typical flow looks like: |
| 36 | + |
| 37 | +``` |
| 38 | +Browser API Gateway (APIG) Authorization Server (AS) |
| 39 | + │ APIG/resource-server-new │ │ |
| 40 | + ├────────────────────────────────────────>│ │ |
| 41 | + │ Location:http://APIG/login │ │ |
| 42 | + │<────────────────────────────────────────│ │ |
| 43 | + │ http://APIG/login │ │ |
| 44 | + ├────────────────────────────────────────>│ │ |
| 45 | + │ Location:http://APIG/AS/oauth/authorize │ │ |
| 46 | + │<────────────────────────────────────────│ │ |
| 47 | + │ http://APIG/AS/oauth/authorize │ │ |
| 48 | + ├────────────────────────────────────────>│ │ |
| 49 | + │ │ /AS/oauth/authorize │ |
| 50 | + │ ├─────────────────────────────────>│ |
| 51 | + │ │ ├──┐ |
| 52 | + │ │ │ │ Not authorized |
| 53 | + │ │ │<─┘ |
| 54 | + │ │ Location:http://APIG/AS/login │ |
| 55 | + │ │<─────────────────────────────────┤ |
| 56 | + │ Location:http://APIG/AS/login │ │ |
| 57 | + │<────────────────────────────────────────│ │ |
| 58 | + │ http://APIGAS/AS/login │ │ |
| 59 | + ├────────────────────────────────────────>│ │ |
| 60 | + │ │ /AS/login │ |
| 61 | + │ ├─────────────────────────────────>│ |
| 62 | + │ │ LOGIN FORM │ |
| 63 | + │ │<─────────────────────────────────┤ |
| 64 | + │ LOGIN FORM │ │ |
| 65 | + │<────────────────────────────────────────┤ │ |
| 66 | +``` |
| 67 | + |
| 68 | +- note that the Authorization Server is internal and never communicates with the outside world |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +## Implementation Notes |
| 73 | + |
| 74 | +### Oauth2ClientContextFilterWithPath |
| 75 | +The custom OAuth2ClientContextFilter now supports URIs (paths), beyond just full URLs. |
| 76 | +We need this path support so that we're able to use it via `security.oauth2.client.userAuthorizationUri` in Zuul, to redirect to Zuul itself. |
| 77 | +Alternatively, we could hardcode this to: `http://localhost:${server.port}/authorization-server-1/oauth/authorize` (not ideal) |
| 78 | + |
| 79 | + |
| 80 | +### `zuul.authorization-server-1.sensitiveHeaders` |
| 81 | +We need the Cookie to be passed through from the Authorization Server |
0 commit comments