-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from mffonseca/feature/refactor-dependency-inj…
…ection Refatorando estrutura para injeção de dependências
- Loading branch information
Showing
19 changed files
with
602 additions
and
424 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"golang.org/x/oauth2" | ||
) | ||
|
||
func CreateOAuthClient(ctx context.Context, oauthConfig *oauth2.Config, token *oauth2.Token) (*http.Client, error) { | ||
client := oauthConfig.Client(ctx, token) | ||
if client == nil { | ||
return nil, fmt.Errorf("failed to create OAuth client") | ||
} | ||
return client, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"golang.org/x/oauth2" | ||
) | ||
|
||
func ExchangeCodeForToken(ctx context.Context, oauthConfig *oauth2.Config, code string) (*oauth2.Token, error) { | ||
token, err := oauthConfig.Exchange(ctx, code) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to retrieve token from web: %v", err) | ||
} | ||
return token, nil | ||
} | ||
|
||
func RefreshToken(ctx context.Context, oauthConfig *oauth2.Config, token *oauth2.Token) (*oauth2.Token, error) { | ||
ts := oauthConfig.TokenSource(ctx, token) | ||
newToken, err := ts.Token() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to refresh token: %v", err) | ||
} | ||
return newToken, nil | ||
} |
Oops, something went wrong.