Skip to content

Instantly share code, notes, and snippets.

@excid3
Created October 22, 2019 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save excid3/ce5d866045f8ff9b12dd0edf1cd082ca to your computer and use it in GitHub Desktop.
Save excid3/ce5d866045f8ff9b12dd0edf1cd082ca to your computer and use it in GitHub Desktop.
class User
def github_student_url
# The School ID GitHub gave you
school_id = "your-school-id"
# The secret key GitHub gave you
secret_key = "secret-key"
# The ID of the student in your database
student_id = id.to_s
# Generate the signature
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), secret_key, school_id + student_id)
"https://education.github.com/student/verify?school_id=#{school_id}&student_id=#{student_id}&signature=#{signature}"
end
end
<%= link_to "GitHub Student", @user.github_student_url %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment