-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add DocC catalog and update all services docs
- Loading branch information
1 parent
b2c85c9
commit ac84c96
Showing
136 changed files
with
419 additions
and
20,230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Getting Started with Imperial | ||
|
||
Federated Authentication with OAuth providers for Vapor. | ||
|
||
## Overview | ||
|
||
Imperial is a Federated Login service, allowing you to easily integrate your Vapor applications with OAuth providers to handle your apps authentication. | ||
|
||
### Sessions Middleware | ||
|
||
Imperial relies on the [sessions middleware](https://docs.vapor.codes/4.0/sessions/#configuration) to save state and access tokens. In **configure.swift**, or as a route group for specific routes, add the sessions middleware. For example, to add it globally: | ||
|
||
```swift | ||
app.middleware.use(app.sessions.middleware) | ||
``` | ||
|
||
### Route Registration | ||
|
||
Imperial uses environment variables to access the client ID and secret to authenticate with the provider. See the provider specific docs for details on what they should be. | ||
|
||
You need to register the OAuth service with your route. For example, to register a GitHub integration add the following: | ||
|
||
```swift | ||
try routes.oAuth(from: GitHub.self, authenticate: "github", callback: "gh-auth-complete") { req, token in | ||
print(token) | ||
return req.redirect(to: "/") | ||
} | ||
``` | ||
|
||
This registers a route to `/github`. When you visit that route, Imperial will trigger the OAuth flow using the `GitHub` service. The callback path is the one registered with the OAuth provider when you create your application. The completion handler is fired when the callback route is called by the OAuth provider. The access token is passed in and a response is returned. | ||
|
||
If you just want to redirect, without doing anything else in the callback, you can use the helper `oAuth(from:authenticate:authenticateCallback:callback:scope:redirect:)` method that takes in a redirect string: | ||
|
||
```swift | ||
try router.oAuth(from: GitHub.self, authenticate: "github", callback: "gh-auth-complete", redirect: "/") | ||
``` | ||
|
||
### Access Tokens and Middleware | ||
|
||
If you ever want to get the `access_token` in a route, you can use a helper method for the `Request` type that comes with Imperial: | ||
|
||
```swift | ||
let token = try request.accessToken | ||
``` | ||
|
||
Now that you are authenticating the user, you will want to protect certain routes to make sure the user is authenticated. You can do this by adding the ``ImperialMiddleware`` to a router group (or maybe your middleware config): | ||
|
||
```swift | ||
let protected = routes.grouped(ImperialMiddleware()) | ||
``` | ||
|
||
Then, add your protected routes to the `protected` group: | ||
|
||
```swift | ||
protected.get("me", use: me) | ||
``` | ||
|
||
The ``ImperialMiddleware`` by default passes the errors it finds onto `ErrorMiddleware` where they are caught, but you can initialize it with a redirect path to go to if the user is not authenticated: | ||
|
||
```swift | ||
let protected = routes.grouped(ImperialMiddleware(redirect: "/")) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# ``ImperialCore`` | ||
|
||
Federated Authentication with OAuth providers for Vapor. | ||
|
||
## Overview | ||
|
||
Imperial is a Federated Login service, allowing you to easily integrate your Vapor applications with OAuth providers to handle your apps authentication. | ||
|
||
The ImperialCore framework provides a set of tools shared by all Imperial provider frameworks. | ||
|
||
## Topics | ||
|
||
### Essentials | ||
|
||
- <doc:GettingStarted> | ||
- ``ImperialCore/Vapor/RoutesBuilder/oAuth(from:authenticate:authenticateCallback:callback:scope:completion:)`` | ||
- ``ImperialCore/Vapor/RoutesBuilder/oAuth(from:authenticate:authenticateCallback:callback:scope:redirect:)`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 11 additions & 6 deletions
17
docs/DeviantArt/README.md → ...ntArt/Documentation.docc/Documentation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
14 changes: 9 additions & 5 deletions
14
docs/Discord/README.md → ...scord/Documentation.docc/Documentation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
# Federated Login with Discord | ||
# ``ImperialDiscord`` | ||
|
||
## Discord Setup | ||
Federated Authentication with Discord for Vapor. | ||
|
||
Start by going to the [Discord Developer Portal](https://discord.com/developers/applications), and creating an "New Application". | ||
## Overview | ||
|
||
### Discord Setup | ||
|
||
Start by going to the [Discord Developer Portal](https://discord.com/developers/applications), and creating a "New Application". | ||
In the "OAuth2" tab click "Add Redirect" and fill in your callback URL. | ||
|
||
## Imperial Integration | ||
### Imperial Integration | ||
|
||
You can use Discord with the `ImperialDiscord` package. This expects two environment variables: | ||
|
||
* `DISCORD_CLIENT_ID` | ||
* `DISCORD_CLIENT_SECRET` | ||
|
||
Additionally you must set `DiscordRouter.callbackURL` to an valid Redirect URL you added in the Developer Portal. | ||
Additionally you must set `callback` to an valid Redirect URL you added in the Developer Portal. | ||
|
||
You can then register the OAuth provider like normal. |
17 changes: 11 additions & 6 deletions
17
docs/Dropbox/README.md → ...opbox/Documentation.docc/Documentation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
Oops, something went wrong.