1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Package endpoints provides constants for using OAuth2 to access various services.
6package endpoints
7
8import (
9	"strings"
10
11	"golang.org/x/oauth2"
12)
13
14// Amazon is the endpoint for Amazon.
15var Amazon = oauth2.Endpoint{
16	AuthURL:  "https://www.amazon.com/ap/oa",
17	TokenURL: "https://api.amazon.com/auth/o2/token",
18}
19
20// Bitbucket is the endpoint for Bitbucket.
21var Bitbucket = oauth2.Endpoint{
22	AuthURL:  "https://bitbucket.org/site/oauth2/authorize",
23	TokenURL: "https://bitbucket.org/site/oauth2/access_token",
24}
25
26// Cern is the endpoint for CERN.
27var Cern = oauth2.Endpoint{
28	AuthURL:  "https://oauth.web.cern.ch/OAuth/Authorize",
29	TokenURL: "https://oauth.web.cern.ch/OAuth/Token",
30}
31
32// Facebook is the endpoint for Facebook.
33var Facebook = oauth2.Endpoint{
34	AuthURL:  "https://www.facebook.com/v3.2/dialog/oauth",
35	TokenURL: "https://graph.facebook.com/v3.2/oauth/access_token",
36}
37
38// Foursquare is the endpoint for Foursquare.
39var Foursquare = oauth2.Endpoint{
40	AuthURL:  "https://foursquare.com/oauth2/authorize",
41	TokenURL: "https://foursquare.com/oauth2/access_token",
42}
43
44// Fitbit is the endpoint for Fitbit.
45var Fitbit = oauth2.Endpoint{
46	AuthURL:  "https://www.fitbit.com/oauth2/authorize",
47	TokenURL: "https://api.fitbit.com/oauth2/token",
48}
49
50// GitHub is the endpoint for Github.
51var GitHub = oauth2.Endpoint{
52	AuthURL:  "https://github.com/login/oauth/authorize",
53	TokenURL: "https://github.com/login/oauth/access_token",
54}
55
56// GitLab is the endpoint for GitLab.
57var GitLab = oauth2.Endpoint{
58	AuthURL:  "https://gitlab.com/oauth/authorize",
59	TokenURL: "https://gitlab.com/oauth/token",
60}
61
62// Google is the endpoint for Google.
63var Google = oauth2.Endpoint{
64	AuthURL:  "https://accounts.google.com/o/oauth2/auth",
65	TokenURL: "https://oauth2.googleapis.com/token",
66}
67
68// Heroku is the endpoint for Heroku.
69var Heroku = oauth2.Endpoint{
70	AuthURL:  "https://id.heroku.com/oauth/authorize",
71	TokenURL: "https://id.heroku.com/oauth/token",
72}
73
74// HipChat is the endpoint for HipChat.
75var HipChat = oauth2.Endpoint{
76	AuthURL:  "https://www.hipchat.com/users/authorize",
77	TokenURL: "https://api.hipchat.com/v2/oauth/token",
78}
79
80// Instagram is the endpoint for Instagram.
81var Instagram = oauth2.Endpoint{
82	AuthURL:  "https://api.instagram.com/oauth/authorize",
83	TokenURL: "https://api.instagram.com/oauth/access_token",
84}
85
86// KaKao is the endpoint for KaKao.
87var KaKao = oauth2.Endpoint{
88	AuthURL:  "https://kauth.kakao.com/oauth/authorize",
89	TokenURL: "https://kauth.kakao.com/oauth/token",
90}
91
92// LinkedIn is the endpoint for LinkedIn.
93var LinkedIn = oauth2.Endpoint{
94	AuthURL:  "https://www.linkedin.com/oauth/v2/authorization",
95	TokenURL: "https://www.linkedin.com/oauth/v2/accessToken",
96}
97
98// Mailchimp is the endpoint for Mailchimp.
99var Mailchimp = oauth2.Endpoint{
100	AuthURL:  "https://login.mailchimp.com/oauth2/authorize",
101	TokenURL: "https://login.mailchimp.com/oauth2/token",
102}
103
104// Mailru is the endpoint for Mail.Ru.
105var Mailru = oauth2.Endpoint{
106	AuthURL:  "https://o2.mail.ru/login",
107	TokenURL: "https://o2.mail.ru/token",
108}
109
110// MediaMath is the endpoint for MediaMath.
111var MediaMath = oauth2.Endpoint{
112	AuthURL:  "https://api.mediamath.com/oauth2/v1.0/authorize",
113	TokenURL: "https://api.mediamath.com/oauth2/v1.0/token",
114}
115
116// MediaMathSandbox is the endpoint for MediaMath Sandbox.
117var MediaMathSandbox = oauth2.Endpoint{
118	AuthURL:  "https://t1sandbox.mediamath.com/oauth2/v1.0/authorize",
119	TokenURL: "https://t1sandbox.mediamath.com/oauth2/v1.0/token",
120}
121
122// Microsoft is the endpoint for Microsoft.
123var Microsoft = oauth2.Endpoint{
124	AuthURL:  "https://login.live.com/oauth20_authorize.srf",
125	TokenURL: "https://login.live.com/oauth20_token.srf",
126}
127
128// NokiaHealth is the endpoint for Nokia Health.
129var NokiaHealth = oauth2.Endpoint{
130	AuthURL:  "https://account.health.nokia.com/oauth2_user/authorize2",
131	TokenURL: "https://account.health.nokia.com/oauth2/token",
132}
133
134// Odnoklassniki is the endpoint for Odnoklassniki.
135var Odnoklassniki = oauth2.Endpoint{
136	AuthURL:  "https://www.odnoklassniki.ru/oauth/authorize",
137	TokenURL: "https://api.odnoklassniki.ru/oauth/token.do",
138}
139
140// PayPal is the endpoint for PayPal.
141var PayPal = oauth2.Endpoint{
142	AuthURL:  "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize",
143	TokenURL: "https://api.paypal.com/v1/identity/openidconnect/tokenservice",
144}
145
146// PayPalSandbox is the endpoint for PayPal Sandbox.
147var PayPalSandbox = oauth2.Endpoint{
148	AuthURL:  "https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize",
149	TokenURL: "https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice",
150}
151
152// Slack is the endpoint for Slack.
153var Slack = oauth2.Endpoint{
154	AuthURL:  "https://slack.com/oauth/authorize",
155	TokenURL: "https://slack.com/api/oauth.access",
156}
157
158// Spotify is the endpoint for Spotify.
159var Spotify = oauth2.Endpoint{
160	AuthURL:  "https://accounts.spotify.com/authorize",
161	TokenURL: "https://accounts.spotify.com/api/token",
162}
163
164// StackOverflow is the endpoint for Stack Overflow.
165var StackOverflow = oauth2.Endpoint{
166	AuthURL:  "https://stackoverflow.com/oauth",
167	TokenURL: "https://stackoverflow.com/oauth/access_token",
168}
169
170// Twitch is the endpoint for Twitch.
171var Twitch = oauth2.Endpoint{
172	AuthURL:  "https://id.twitch.tv/oauth2/authorize",
173	TokenURL: "https://id.twitch.tv/oauth2/token",
174}
175
176// Uber is the endpoint for Uber.
177var Uber = oauth2.Endpoint{
178	AuthURL:  "https://login.uber.com/oauth/v2/authorize",
179	TokenURL: "https://login.uber.com/oauth/v2/token",
180}
181
182// Vk is the endpoint for Vk.
183var Vk = oauth2.Endpoint{
184	AuthURL:  "https://oauth.vk.com/authorize",
185	TokenURL: "https://oauth.vk.com/access_token",
186}
187
188// Yahoo is the endpoint for Yahoo.
189var Yahoo = oauth2.Endpoint{
190	AuthURL:  "https://api.login.yahoo.com/oauth2/request_auth",
191	TokenURL: "https://api.login.yahoo.com/oauth2/get_token",
192}
193
194// Yandex is the endpoint for Yandex.
195var Yandex = oauth2.Endpoint{
196	AuthURL:  "https://oauth.yandex.com/authorize",
197	TokenURL: "https://oauth.yandex.com/token",
198}
199
200// AzureAD returns a new oauth2.Endpoint for the given tenant at Azure Active Directory.
201// If tenant is empty, it uses the tenant called `common`.
202//
203// For more information see:
204// https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols#endpoints
205func AzureAD(tenant string) oauth2.Endpoint {
206	if tenant == "" {
207		tenant = "common"
208	}
209	return oauth2.Endpoint{
210		AuthURL:  "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/authorize",
211		TokenURL: "https://login.microsoftonline.com/" + tenant + "/oauth2/v2.0/token",
212	}
213}
214
215// HipChatServer returns a new oauth2.Endpoint for a HipChat Server instance
216// running on the given domain or host.
217func HipChatServer(host string) oauth2.Endpoint {
218	return oauth2.Endpoint{
219		AuthURL:  "https://" + host + "/users/authorize",
220		TokenURL: "https://" + host + "/v2/oauth/token",
221	}
222}
223
224// AWSCognito returns a new oauth2.Endpoint for the supplied AWS Cognito domain which is
225// linked to your Cognito User Pool.
226//
227// Example domain: https://testing.auth.us-east-1.amazoncognito.com
228//
229// For more information see:
230// https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-assign-domain.html
231// https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-userpools-server-contract-reference.html
232func AWSCognito(domain string) oauth2.Endpoint {
233	domain = strings.TrimRight(domain, "/")
234	return oauth2.Endpoint{
235		AuthURL:  domain + "/oauth2/authorize",
236		TokenURL: domain + "/oauth2/token",
237	}
238}
239