gitea

Development moved to Codeberg

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
# Nextcloud OAuth2

For this backend, you need to have an OAuth2 enabled Nextcloud Instance, e.g.
on your own private server.

## Setting up Nextcloud Test Environment

To test, you only need a working Docker image of Nextcloud running on a public
URL, e.g. through [traefik](https://traefik.io/)

```docker-compose.yml
version: '2'

networks:
  traefik-web:
    external: true

services:
  app:
    image: nextcloud
    restart: always
    networks:
      - traefik-web
    labels:
      - traefik.enable=true
      - traefik.frontend.rule=Host:${NEXTCLOUD_DNS}
      - traefik.docker.network=traefik-web
    environment:
      SQLITE_DATABASE: "database.sqlite3"
      NEXTCLOUD_ADMIN_USER: admin
      NEXTCLOUD_ADMIN_PASSWORD: admin
      NEXTCLOUD_TRUSTED_DOMAINS: ${NEXTCLOUD_DNS}
```

and start it up via

```
NEXTCLOUD_DNS=goth.my.server.name docker-compose up -d
```

afterwards, you will have a running Nextcloud instance with credentials

```
admin / admin
```

Then add a new OAuth 2.0 Client by going to

```
Settings -> Security -> OAuth 2.0 client
```

![Nextcloud Setup](nextcloud_setup.png)

and add a new client with the name `goth` and redirection uri `http://localhost:3000/auth/nextcloud/callback`. The imporant part here the
two cryptic entries `Client Identifier` and `Secret`, which needs to be
used in your application.

## Running Login Example

If you want to run the default example in `<goth>/examples`, you have to 
retrieve the keys described in the previous section and run the example
as follows:

```
NEXTCLOUD_URL=https://goth.my.server.name \
NEXTCLOUD_KEY=<your-key> \
NEXTCLOUD_SECRET=<your-secret> \
SESSION_SECRET=1 \
./examples
```

Afterwards, you should be able to login via Nextcloud in the examples app.

## Running the Provider Test

The test has the same arguments as the login example test, but starts the test itself

```
NEXTCLOUD_URL=https://goth.my.server.name \
NEXTCLOUD_KEY=<your-key> \
NEXTCLOUD_SECRET=<your-secret> \
SESSION_SECRET=1 \
go test -v
```