mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-17 09:29:30 +08:00
[v3] Update readme for oauth
plugin
This commit is contained in:
parent
3f55ce6dfc
commit
1fc5f9b12d
@ -92,7 +92,7 @@ func main() {
|
|||||||
Plugins: map[string]application.Plugin{
|
Plugins: map[string]application.Plugin{
|
||||||
"oauth": oAuthPlugin,
|
"oauth": oAuthPlugin,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
@ -124,12 +124,12 @@ type Config struct {
|
|||||||
If you don't specify a `WindowConfig`, the plugin will use the default window configuration:
|
If you don't specify a `WindowConfig`, the plugin will use the default window configuration:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
&application.WebviewWindowOptions{
|
&application.WebviewWindowOptions{
|
||||||
Title: "OAuth Login",
|
Title: "OAuth Login",
|
||||||
Width: 600,
|
Width: 600,
|
||||||
Height: 850,
|
Height: 850,
|
||||||
Hidden: true,
|
Hidden: true,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -139,18 +139,18 @@ If you don't specify a `WindowConfig`, the plugin will use the default window co
|
|||||||
You can start the flow by calling one of the provider methods:
|
You can start the flow by calling one of the provider methods:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
err := oAuthPlugin.Github()
|
err := oAuthPlugin.Github()
|
||||||
```
|
```
|
||||||
|
|
||||||
In this example, we send an event from the frontend to start the process, so we listen for the event in the backend:
|
In this example, we send an event from the frontend to start the process, so we listen for the event in the backend:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
app.Events.On("github-login", func(e *application.WailsEvent) {
|
app.Events.On("github-login", func(e *application.WailsEvent) {
|
||||||
err := oAuthPlugin.Github()
|
err := oAuthPlugin.Github()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// process error
|
// process error
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### JavaScript
|
### JavaScript
|
||||||
@ -158,7 +158,7 @@ In this example, we send an event from the frontend to start the process, so we
|
|||||||
You can start the flow by calling one of the provider methods:
|
You can start the flow by calling one of the provider methods:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
await wails.Plugin("oauth","Github")
|
await wails.Plugin("oauth","Github")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Handling Success & Failure
|
### Handling Success & Failure
|
||||||
@ -171,30 +171,30 @@ When the OAuth flow completes, the plugin will send one of 2 events:
|
|||||||
In Javascript, we can listen for these events like so:
|
In Javascript, we can listen for these events like so:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
window.wails.Events.On("wails:oauth:success", (event) => {
|
window.wails.Events.On("wails:oauth:success", (event) => {
|
||||||
document.getElementById("main").style.display = "none";
|
document.getElementById("main").style.display = "none";
|
||||||
document.getElementById("name").innerText = event.data.Name;
|
document.getElementById("name").innerText = event.data.Name;
|
||||||
document.getElementById("logo").src = event.data.AvatarURL;
|
document.getElementById("logo").src = event.data.AvatarURL;
|
||||||
document.body.style.backgroundColor = "#000";
|
document.body.style.backgroundColor = "#000";
|
||||||
document.body.style.color = "#FFF";
|
document.body.style.color = "#FFF";
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to handle them in Go, you can do so like this:
|
If you want to handle them in Go, you can do so like this:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
app.Events.On("wails:oauth:success", func(e *application.WailsEvent) {
|
app.Events.On("wails:oauth:success", func(e *application.WailsEvent) {
|
||||||
// Do something with the user data
|
// Do something with the user data
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
Both these events are constants in the plugin:
|
Both these events are constants in the plugin:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
const (
|
const (
|
||||||
Success = "wails:oauth:success"
|
Success = "wails:oauth:success"
|
||||||
Error = "wails:oauth:error"
|
Error = "wails:oauth:error"
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
There is a working example of GitHub auth in the `v3/examples/oauth` directory.
|
There is a working example of GitHub auth in the `v3/examples/oauth` directory.
|
||||||
|
Loading…
Reference in New Issue
Block a user