If you have questions about this application, there was a bug or there are suggestions for improvement, then you can ask it in Issues, or in t.me/zergsLaw
login := passport.New(
github.OAuth(githubCfg),
)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
code := "AUTH_CODE"
account, token, err := login.Account(ctx, github.ID, code)
if err != nil {
log.Fatal(err)
}
log.Println("account:", account)
log.Println("token type:", token.TokenType)
Initiate a module for a social network.
githubClient := github.New(githubCfg)
You initiate the library.
login := passport.New(
// The parameters are used to transmit the social network required for its operation and assign id.
passport.OAuthClient(github.ID, githubClient),
// or use a wrapper that all standard modules have.
github.OAuth(githubCfg),
)
To expand the library with its modules, all you have to do is implement this interface. You initiate the library.
type OauthClient interface {
Token(ctx context.Context, code string) (*oauth2.Token, error)
Account(ctx context.Context, token *oauth2.Token) (*Account, error)
}
And when initializing the application, send your social network by the parameter.
login := passport.New(
passport.OAuthClient(youID, youSocialClient),
)