Skip to main content

Sign-in third-party services

This page describes how to perform a sign-in third-party services through OAuth 2.0 flows.

Known OAuth 2.0 flows

The following list contains the currently known OAuth 2.0 flows.

ProviderStatusValue
MyAnimeListSUPPORTEDusers/[...]/flows/myanimelist-net
AniListSUPPORTEDusers/[...]/flows/anilist-co

Sample

The following sample shows how to perform a sign-in third-party services through OAuth 2.0 flows.

Replace [FLOW] with the desired sign-in flow, e.g. users/123/flows/myanimelist-net.

tip

Tip: do not forget to replace CLIENT-ID and CLIENT-SECRET with valid IAM Service Account client credentials.

package main

import (
"context"
"log"

"golang.org/x/oauth2/clientcredentials"

"google.golang.org/api/option"

gapic "github.com/animeapis/api-go-client/credentials/v1alpha1"
credentials "github.com/animeapis/go-genproto/credentials/v1alpha1"
)

var (
Flow = "[FLOW]"

ClientID = "[CLIENT-ID]"
ClientSecret = "[CLIENT-SECRET]"
)

var (
TokenURL = "https://accounts.animeshon.com/o/oauth2/token"
Endpoint = "credentials.animeapis.com:443"
)

func main() {
ctx := context.Background()

config := &clientcredentials.Config{
ClientID: ClientID,
ClientSecret: ClientSecret,
TokenURL: TokenURL,
}

options := []option.ClientOption{
option.WithEndpoint(Endpoint),
option.WithTokenSource(config.TokenSource(ctx)),
}

client, err := gapic.NewOAuth2Client(ctx, options...)
if err != nil {
log.Fatalf("NewOAuth2Client: %s", err)
}

request := &credentials.SignInRequest{
Name: Flow,
}

response, err := client.SignIn(ctx, request)
if err != nil {
log.Fatalf("SignIn: %s", err)
}

log.Printf("authorization url: %s", response.AuthorizationUrl)
}
View on GitHub