# OAuth

If you're using [OAuth](/oauth.md) to manage user authentication, you may find you need to generate login URLs at some point. Here's how you do it.

## Generating login URLs

Here's the regular/parameter syntax in action, especially useful if the provider name comes from variable.

::tabs

::tab antlers
```antlers
<a href="{{ oauth provider="github" }}">Sign In with Github</a>
```
::tab blade
```blade
<a href="{{ Statamic::tag('oauth')->provider('github') }}">Sign In with Github</a>
```
::

```output
<a href="/oauth/github">Sign In with Github</a>
```

And the shorthand version.

::tabs

::tab antlers
```antlers
<a href="{{ oauth:github }}">Sign In with Github</a>
```
::tab blade
```blade
<a href="{{ Statamic::tag('oauth:github') }}">Sign In with Github</a>
```
::

```html
<a href="/oauth/github">Sign In with Github</a>
```

And now with a redirect:

::tabs

::tab antlers
```antlers
<a href="{{ oauth:github redirect="/account" }}">Sign In with Github</a>
```
::tab blade
```blade
<a href="{{ Statamic::tag('oauth:github')->redirect('/account') }}">Sign In with Github</a>
```
::

```html
<a href="/oauth/github?redirect=/account">Sign In with Github</a>
```

## Looping through providers

Use `{{ oauth }} ... {{ /oauth }}` as a tag pair to loop through the configured providers. This is useful for building your own [connected-accounts](/oauth.md#connecting-accounts) UI, since each provider tells you whether the current user has connected it.

Providers configured as [`stateless`](/oauth.md#providers) are excluded from the loop, since they can't be used for connecting accounts.

::tabs

::tab antlers
```antlers
<ul>
    {{ oauth }}
        <li>
            {{ if connected }}
                {{ oauth:disconnect_form :provider="name" }}
                    <button type="submit">Disconnect {{ label }}</button>
                {{ /oauth:disconnect_form }}
            {{ else }}
                <a href="{{ url }}">Connect {{ label }}</a>
            {{ /if }}
        </li>
    {{ /oauth }}
</ul>
```
::tab blade
```blade
<ul>
    <s:oauth>
        <li>
            @if ($connected)
                <s:oauth:disconnect_form :provider="$name">
                    <button type="submit">Disconnect {{ $label }}</button>
                </s:oauth:disconnect_form>
            @else
                <a href="{{ $url }}">Connect {{ $label }}</a>
            @endif
        </li>
    </s:oauth>
</ul>
```
::
